From: Noel B. (JIRA) <no...@at...> - 2006-01-26 01:46:17
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-120?page=comments#action_21822 ] Noel Bush commented on ANN-120: ------------------------------- I'm hoping I can come up with a simple patch -- Hibernate and the Annotations project are pretty complex, but I believe I see the place where this formula is generated. But I am really curious about your point of view that this isn't important. You've mentioned that before, and perhaps I am just misunderstanding something, but I cannot understand how it would not seem *essential* that Hibernate (with or without Annotations) should be able to persist members of a class that are Maps, just like any other member of a class. You don't think that Maps themselves are inessential, do you? If I adopt the position that Maps are not important because they don't match up neatly with a relational model, then I am basically saying that I have to re-work my application to work only in terms that are "friendly" to relational concepts. And this seems to be in the wrong direction, purpose-wise, from what ORM tools are supposed to be. But I say all this out of naivete, without a solid background in relational modeling. I admit that I'm one of the people looking for something that "just works", rather than requiring me to become a database expert. In any case, I will try my (limited) best to come up with a patch that deals with this issue, and will see if it is actually usable in the grander scheme of all things Hibernate. > 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: Bug > Components: binder > Versions: 3.1beta6 > Environment: Hibernate 3.1 RC1, Annotations 3.1b6, Java 1.5.0_05 > Reporter: Mattias Arbin > Attachments: KeyValue.java, MyEntity.java, TestKeyValue.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 |