-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: @MapKey with @OneToMany and @JoinTable does not work
PostPosted: Sat Jan 07, 2006 5:41 pm 
Newbie

Joined: Sat Jan 07, 2006 5:18 pm
Posts: 19
The following mapping generates an exception when loading from the database:

Code:
@OneToMany
@MapKey(name = "sourceType")
@Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinTable(table = @Table(name = "CaptureDescription_CaptureDescriptionSources"), joinColumns = { @JoinColumn(name = "captureDescriptionId") }, inverseJoinColumns = { @JoinColumn(name = "captureDescriptionSourceId") })
public Map<CaptureDescriptionSourceType, CaptureDescriptionSource> getSources()
{
    return sources;
}

From examining the generated SQL in the stack trace, Hibernate is looking for the column "sourceType" on the join table CaptureDescription_CaptureDescriptionSources instead of the left outer join table CaptureDescriptionSources. This is a uni-directional @OneToMany relationship, so the CaptureDescriptionSource entity does not know about the CaptureDescription entity. Any ideas what's going on here? This seems to be a very straightforward mapping.

Hibernate version: 3.1 final

Mapping documents: using annotations

Code between sessionFactory.openSession() and session.close(): using Spring getHibernateTemplate()

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 5.0.16-nt

The generated SQL (show_sql=true):

Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not initialize a collection: [com.compudata.daf.domain.CaptureDescription.sources#1]; bad SQL grammar [select sources0_.captureDescriptionId as captureD1_1_, sources0_.captureDescriptionSourceId as captureD2_1_, sources0_.sourceType as formula2_1_, capturedes1_.id as id6_0_, capturedes1_.sleepTime as sleepTime6_0_, capturedes1_.sourceType as sourceType6_0_, capturedes1_.sourceDir as sourceDir6_0_ from CaptureDescription_CaptureDescriptionSources sources0_ left outer join CaptureDescriptionSource capturedes1_ on sources0_.captureDescriptionSourceId=capturedes1_.id where sources0_.captureDescriptionId=?]; nested exception is java.sql.SQLException: Unknown column 'sources0_.sourceType' in 'field list'
java.sql.SQLException: Unknown column 'sources0_.sourceType' in 'field list'
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2281)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1634)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
   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:1627)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentMap.values(PersistentMap.java:198)
   at org.hibernate.type.MapType.getElementsIterator(MapType.java:39)
   at org.hibernate.type.CollectionType.getElementsIterator(CollectionType.java:188)
   at org.hibernate.engine.CascadingAction.getAllElementsIterator(CascadingAction.java:266)
   at org.hibernate.engine.CascadingAction.access$100(CascadingAction.java:21)
   at org.hibernate.engine.CascadingAction$2.getCascadableChildrenIterator(CascadingAction.java:52)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:288)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:223)
   at org.hibernate.event.def.DefaultDeleteEventListener.cascadeBeforeDelete(DefaultDeleteEventListener.java:220)
   at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:169)
   at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:110)
   at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:764)
   at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:757)
   at org.hibernate.engine.CascadingAction$2.cascade(CascadingAction.java:47)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:223)
   at org.hibernate.event.def.DefaultDeleteEventListener.cascadeBeforeDelete(DefaultDeleteEventListener.java:220)
   at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:169)
   at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:110)
   at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:764)
   at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:743)
   at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:746)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
   at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:740)
   at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:736)
   at com.compudata.daf.data.hibernate.RepositoryDaoHibernate.delete(RepositoryDaoHibernate.java:31)
   at com.compudata.daf.business.EnvironmentManager.deleteRepository(EnvironmentManager.java:134)
   at com.compudata.daf.business.EnvironmentManagerTests.testDeleteRepository(EnvironmentManagerTests.java:88)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 2:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is not supported

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 5:34 pm 
Newbie

Joined: Sat Jan 07, 2006 5:18 pm
Posts: 19
So Hibernate doesn't support a mapped one-to-many relationship? Is it going to be implemented in the future? The documentation doesn't say anywhere that it isn't supported, so that should probably be amended.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 5:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is an open JIRA issue if I recall

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 10:05 am 
Newbie

Joined: Sat Jan 07, 2006 5:18 pm
Posts: 19
Ok, good to hear - so it sounds like you're saying that it will probably be implemented in the future, it's just not working now. I can live with that. Thanks for the great tool!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.