[Hibernate-JIRA] Resolved: (ANN-374) Map - OneToMany w or w/o join table creates bad sql
by Emmanuel Bernard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-374?page=all ]
Emmanuel Bernard resolved ANN-374:
----------------------------------
Resolution: Fixed
I do have a working testcase, I'm pretty sure it has been resolved in earlier releases though
> Map - OneToMany w or w/o join table creates bad sql
> ---------------------------------------------------
>
> Key: ANN-374
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-374
> Project: Hibernate Annotations
> Type: Improvement
> Components: binder
> Versions: 3.1beta6
> Environment: Hibernate 3.1 RC1, Annotations 3.1b6, Java 1.5.0_05
> Reporter: Todd O
> Assignee: Emmanuel Bernard
> Fix For: 3.2.0.cr2
> Attachments: KeyValue2.java, MyEntity2.java, TestKeyValue2.java
>
>
> Seems like there is a problem with mapping a Map using join table.
> I have a relation like this:
> @OneToMany(cascade=CascadeType.ALL)
> @MapKey(name="name")
> public Map<String, KeyValue> getProps() {
> return props;
> }
> The correct tables are created and inserting data works fine. When loading, however, I get the error below.
> When using a join column, everything works fine:
> @OneToMany(cascade=CascadeType.ALL)
> @MapKey(name="name")
> @JoinColumn(name="myentity_id")
> public Map<String, KeyValue> getProps() {
> return props;
> }
> Attached the two test classes.
> The error:
> ...
> Hibernate: select this_.id as id3_0_ from test_MyEntity this_
> Hibernate: select props0_.MyEntity_id as MyEntity1_1_, props0_.props_id as props2_1_, props0_.name as formula0_1_, keyvalue1_.id as id2_0_, keyvalue1_.val as val2_0_, keyvalue1_.name as name2_0_ from test_MyEntity_KeyValue props0_ left outer join test_KeyValue keyvalue1_ on props0_.props_id=keyvalue1_.id where props0_.MyEntity_id=?
> 15:11:49,078 WARN JDBCExceptionReporter:71 - SQL Error: 1054, SQLState: 42S22
> Exception in thread "main" 15:11:49,078 ERROR JDBCExceptionReporter:72 - null, message from server: "Unknown column 'props0_.name' in 'field list'"
> org.hibernate.exception.SQLGrammarException: could not initialize a collection: [test.data.MyEntity.props#1]
> at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
> at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
> at org.hibernate.loader.Loader.loadCollection(Loader.java:1923)
> at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
> at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
> at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
> at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1565)
> at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
> at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
> at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:161)
> at org.hibernate.collection.PersistentMap.get(PersistentMap.java:127)
> at test.TestKeyValue.test(TestKeyValue.java:43)
> at test.TestKeyValue.main(TestKeyValue.java:57)
> Caused by: java.sql.SQLException: null, message from server: "Unknown column 'props0_.name' in 'field list'"
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
> at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
> at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
> at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
> at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1496)
> at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
> at org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
> at org.hibernate.loader.Loader.doQuery(Loader.java:662)
> at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
> at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
> ... 10 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months
[Hibernate-JIRA] Resolved: (ANN-181) Do not fail on unbound attributes marked as @Type
by Emmanuel Bernard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-181?page=all ]
Emmanuel Bernard resolved ANN-181:
----------------------------------
Resolution: Fixed
Assign To: Emmanuel Bernard (was: Paolo "Nusco" Perrotta)
> Do not fail on unbound attributes marked as @Type
> -------------------------------------------------
>
> Key: ANN-181
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-181
> Project: Hibernate Annotations
> Type: Bug
> Components: binder
> Versions: 3.1beta7
> Reporter: Ryan Dewell
> Assignee: Emmanuel Bernard
> Fix For: 3.2.0.cr2
>
>
> Exception is thrown by PropertyInferredData at extractType when handling a generically typed entity. This problem did not exist in previous versions of PropertyInferredData where "method.getReturnType()" was used to extract the type instead.
> Workaround patch (falls back to original procedure):
> --------------------------------
> try {
> returnedClass = extractType(type);
> } catch (Exception e){
> returnedClass = method.getReturnType();
> }
> Example generic entity:
> --------------------------------
> package com.brightmarket.core.workflow;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Table;
> import org.hibernate.annotations.Type;
> import org.hibernate.validator.NotNull;
> import com.brightmarket.core.Model;
> @Entity(name="LifecycleHistory")
> @Table(name="workflow_lifecycle_history")
> public class LifecycleHistory<STATE extends Enum, REASON extends Enum> extends Model{
> private static final long serialVersionUID = -8445979354786791933L;
> private STATE previousLifecycle;
> private STATE newLifecycle;
> private REASON newLifecycleReason;
>
> @Column(name="new_lifecycle")
> @NotNull
> @Type(type="StringEnum")
> public STATE getNewLifecycle() {
> return newLifecycle;
> }
> public void setNewLifecycle(STATE lifecycle) {
> this.newLifecycle = lifecycle;
> }
>
> @Column(name="new_lifecycle_reason")
> @Type(type="StringEnum")
> public REASON getNewLifecycleReason() {
> return newLifecycleReason;
> }
> public void setNewLifecycleReason(REASON lifecycle) {
> this.newLifecycleReason = lifecycle;
> }
>
> // NOTE: this isn't strictly needed because it should be accessible via the date stamped lifecycle history occuring prior to this entry.
> @Column(name="previous_lifecycle")
> @Type(type="StringEnum")
> public STATE getPreviousLifecycle() {
> return previousLifecycle;
> }
> public void setPreviousLifecycle(STATE previousLifecycle) {
> this.previousLifecycle = previousLifecycle;
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months
[Hibernate-JIRA] Updated: (ANN-181) Do not fail on unbound attributes marked as @Type
by Emmanuel Bernard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-181?page=all ]
Emmanuel Bernard updated ANN-181:
---------------------------------
Summary: Do not fail on unbound attributes marked as @Type (was: PropertyInferredData fails on generic entities)
> Do not fail on unbound attributes marked as @Type
> -------------------------------------------------
>
> Key: ANN-181
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-181
> Project: Hibernate Annotations
> Type: Bug
> Components: binder
> Versions: 3.1beta7
> Reporter: Ryan Dewell
> Assignee: Paolo "Nusco" Perrotta
> Fix For: 3.2.0.cr2
>
>
> Exception is thrown by PropertyInferredData at extractType when handling a generically typed entity. This problem did not exist in previous versions of PropertyInferredData where "method.getReturnType()" was used to extract the type instead.
> Workaround patch (falls back to original procedure):
> --------------------------------
> try {
> returnedClass = extractType(type);
> } catch (Exception e){
> returnedClass = method.getReturnType();
> }
> Example generic entity:
> --------------------------------
> package com.brightmarket.core.workflow;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Table;
> import org.hibernate.annotations.Type;
> import org.hibernate.validator.NotNull;
> import com.brightmarket.core.Model;
> @Entity(name="LifecycleHistory")
> @Table(name="workflow_lifecycle_history")
> public class LifecycleHistory<STATE extends Enum, REASON extends Enum> extends Model{
> private static final long serialVersionUID = -8445979354786791933L;
> private STATE previousLifecycle;
> private STATE newLifecycle;
> private REASON newLifecycleReason;
>
> @Column(name="new_lifecycle")
> @NotNull
> @Type(type="StringEnum")
> public STATE getNewLifecycle() {
> return newLifecycle;
> }
> public void setNewLifecycle(STATE lifecycle) {
> this.newLifecycle = lifecycle;
> }
>
> @Column(name="new_lifecycle_reason")
> @Type(type="StringEnum")
> public REASON getNewLifecycleReason() {
> return newLifecycleReason;
> }
> public void setNewLifecycleReason(REASON lifecycle) {
> this.newLifecycleReason = lifecycle;
> }
>
> // NOTE: this isn't strictly needed because it should be accessible via the date stamped lifecycle history occuring prior to this entry.
> @Column(name="previous_lifecycle")
> @Type(type="StringEnum")
> public STATE getPreviousLifecycle() {
> return previousLifecycle;
> }
> public void setPreviousLifecycle(STATE previousLifecycle) {
> this.previousLifecycle = previousLifecycle;
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months