Register / Login
Win a copy of
Java Mock Exams (software)
this week in the
Programmer Certification (OCPJP)
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
Object Relational Mapping
Hibernate : Groups of Groups / IllegalArgumentException calling getter
posted 7 years ago
I'm struggling to find out the proper way to represent the following relationship within hibernate :
MyGroup: id : Integer text : String childGroups : Set<MyGroup>() MyGroupGroups: id : Integer parent : MyGroup child : MyGroup
I'd like to have, in effect, groups of groups and am using the MyGroupGroups table as a join table from MyGroup to tie back to the child groups.
MyGroup.hbm.xml (fragment) :
... <set name="childGroups" inverse="true"> <key> <column name="parent" not-null="true" /> </key> <one-to-many class="MyGroupGroups" /> </set>
and within the childGroupGroups.hbm.xml I have the following :
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="MyGroupGroups" table="myGroupGroups" schema="public"> <id name="id" type="Integer"> <column name="id" /> <generator class="assigned" /> </id> <many-to-one name="parent" class="MyGroup" fetch="select"> <column name="parentGroup" not-null="true" /> </many-to-one> <many-to-one name="child" class="MyGroup" fetch="select"> <column name="childGroup" not-null="true" /> </many-to-one> </class> </hibernate-mapping>
When all is said and done I'm receiving a
nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of MyGroupGroups.id
Note : I did have to go through and manually replace the MyGroup / MyGroupGroups elements - please adjust your reading glasses accordingly as I may have misapplied some changes.
posted 7 years ago
Banging my head repeatdly against the issue resolved the problem :
Modifying the MyGroup.hbm.xml to reflect this, made it work.
... <set name="childGroups" table="MyGroup" inverse="true" lazy="true"> <key column="parent" /> <element type="MyGroupGroups" column="child" /> </set>
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
Boost this thread!
what changes should i made in save method in one-to-many relationships
Querying tables with a one-to-many foreign key relationship
Cascading non foreign key to Child Table
Parent Key Not Found Error
Hibernate - Force foreign key lookup on insert