[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-120) Map, OneToMany, join table or @ManyToMany does not work
Odd Möller (JIRA)
noreply at atlassian.com
Tue Aug 15 04:35:23 EDT 2006
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-120?page=comments#action_23935 ]
Odd Möller commented on ANN-120:
--------------------------------
Maybe this is a known problem/limitation, but the changes done (to resolve this issue) in revision 9894 to the createFormulatedValue method (line 271) of the org.hibernate.cfg.annotations.MapBinder class, seperates conditions (when multiple collection columns exist) in the where clause with a comma (',') instead of 'and'. This results in a malformed SQL syntax exception (at least with HSQLDB). When I change the ',' to 'and' the exception does not occur.
> Map, OneToMany, join table or @ManyToMany does not work
> -------------------------------------------------------
>
> Key: ANN-120
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-120
> Project: Hibernate Annotations
> Type: Improvement
> Components: binder
> Versions: 3.1beta6
> Environment: Hibernate 3.1 RC1, Annotations 3.1b6, Java 1.5.0_05
> Reporter: Mattias Arbin
> Assignee: Emmanuel Bernard
> Fix For: 3.2.0.cr1
> Attachments: KeyValue.java, KeyValue2.java, MyEntity.java, MyEntity2.java, TestKeyValue.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.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list