[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2598) Mapping a collection of entities from two different classes with the same collection name results in duplicate backref property exception if collection keys are not null
Diego Pires Plentz (JIRA)
noreply at atlassian.com
Fri Oct 5 08:58:40 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28371 ]
Diego Pires Plentz commented on HHH-2598:
-----------------------------------------
Fixed in trunk/3.2
thanks
> Mapping a collection of entities from two different classes with the same collection name results in duplicate backref property exception if collection keys are not null
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-2598
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2598
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.1, 3.2.2, 3.2.3
> Environment: Proven on Hibernate 3.2.2 and 3.2.3, PostgreSQL 8.2.3, WindowsXP, Java 1.5
> Reporter: Guido Scalise
> Assignee: Diego Pires Plentz
> Fix For: 3.2.6
>
> Attachments: backref.patch, Hibernate-bug.zip
>
>
> Mapping a child entity collection from two different parent entities results in duplicate backref property exception when configuring the session factory if the collection keys are marked not null and the collection names are the same in both parents.
> Log is:
> (cfg.Environment 509 ) Hibernate 3.2.3
> (cfg.Environment 542 ) hibernate.properties not found
> (cfg.Environment 676 ) Bytecode provider name : cglib
> (cfg.Environment 593 ) using JDK 1.4 java.sql.Timestamp handling
> (cfg.Configuration 1426) configuring from resource: /hibernate.cfg.xml
> (cfg.Configuration 1403) Configuration resource: /hibernate.cfg.xml
> (cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/ParentA.hbm.xml
> (cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.ParentA -> PARENT_A
> (cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/ParentB.hbm.xml
> (cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.ParentB -> PARENT_B
> (cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/Child.hbm.xml
> (cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.Child -> CHILD
> (cfg.Configuration 1541) Configured SessionFactory: null
> (cfg.HbmBinder 2375) Mapping collection: com.bbsw.tests.ParentA.children -> CHILD
> (cfg.HbmBinder 2375) Mapping collection: com.bbsw.tests.ParentB.children -> CHILD
> Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of _childrenBackref found in com.bbsw.tests.Child
> at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:459)
> at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:449)
> at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
> at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
> at HBTest.main(HBTest.java:17)
> The problem seems to be originated during the second Collection binding pass in org.hibernate.cfg.HbmBinder, as the Backrefs and IndexBackrefs names are created like this:
> (Excerpts from HbmBinder.java r10921 2006-12-05 14:39:12Z steve.ebersole at jboss.com, contained in the Hibernate 3.2.3.ga source)
> line 2242: IndexBackref ib = new IndexBackref();
> line 2243: ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" );
> and
> line 2478: Backref prop = new Backref();
> line 2479: prop.setName( '_' + node.attributeValue( "name" ) + "Backref" );
> in both cases the node name value is the collection name. So for every collection that points to a child, Hibernate creates a backref property without considering the posibility of more than one entity declaring the same collection name.
> I've patched the code to add the collection owner's entity name to the property name, and it worked without problems.
> I'm attaching:
> * ParentA, ParentB and Child classes
> * Mappings for ParentA, ParentB and Child
> * hbm.xml file
> * Main test case. (HBTest.java)
> * Proposed patch in unified diff format.
--
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