From: Daniel H. (JIRA) <no...@at...> - 2006-07-20 16:07:15
|
Mapping a many-to-many to part of the target's composite PK doesn't work ------------------------------------------------------------------------- Key: HHH-1926 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1926 Project: Hibernate3 Type: Bug Components: core Versions: 3.1.3 Environment: Tested on 3.1.3 and 3.2.0.cr2 Reporter: Daniel Hannum Attachments: hibernateTest.zip Hi, I brought this up on the forums: http://forum.hibernate.org/viewtopic.php?p=2315103#2315103 And although I received some guidance, it still doesn't work. Perhaps it's a bug, perhaps it's impossible, perhaps a wider audience can help... here goes. Consider class A with a 3-way PK: C1, C2, C3 class B with a 4-way PK: C2, C3, C4, C5 As you can see A and B share two columns. This is a many-to-many relation with no join table, and yes I know it's poor database design. It's legacy, can't change it, etc. All I want is for Hibernate, when creating a persistent A, to efficiently retrieve a bag of all B's that share the two shared columns. The reverse mapping is optional. I don't need to be able to update this collection, just read the B's without having to issue separate DB hits. Unfortunately, Hibernate is still unhappy with my mappings (below) org.hibernate.MappingException: collection element mapping has wrong number of columns: hibernatetest.B.relatedAs type: hibernatetest.A A.hbm.xml is <composite-id name="compId" class="hibernatetest.APK"> <key-property name="column1" column="C1" /> <key-property name="column2" column="C2" /> <key-property name="column3" column="C3" /> </composite-id> <property name="otherColumnA" column="OTHER_COLUMN_A" /> <properties name="keysSharedA"> <property name="column2" column="C2" insert="false" update="false"/> <property name="column3" column="C3" insert="false" update="false"/> </properties> <bag name="relatedBs"> <key property-ref="keysSharedA"> <column name="C2"/> <column name="C3"/> </key> <many-to-many class="hibernatetest.B"/> </bag> B.hbm.xml is very similar <composite-id name="compId" class="hibernatetest.BPK"> <key-property name="column2" column="C2" /> <key-property name="column3" column="C3" /> <key-property name="column4" column="C4" /> <key-property name="column5" column="C5" /> </composite-id> <property name="otherColumnB" column="OTHER_COLUMN_B" /> <properties name="keysSharedB"> <property name="column2" column="C2" insert="false" update="false"/> <property name="column3" column="C3" insert="false" update="false"/> </properties> <bag name="relatedAs" inverse="true"> <key property-ref="keysSharedB"> <column name="C2"/> <column name="C3"/> </key> <many-to-many class="hibernatetest.A"/> </bag> I have attached a zip containing the code and mapping files, as well as a unit test that displays the problem. Thanks for any help you can provide. -- 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 |