A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Object Relational Mapping
Hibernate : Groups of Groups / IllegalArgumentException calling getter
Joined: Jul 17, 2008
Mar 24, 2009 09:38:24
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.
Joined: Jul 17, 2008
Mar 24, 2009 13:38:14
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>
I agree. Here's the link:
subject: Hibernate : Groups of Groups / IllegalArgumentException calling getter
what changes should i made in save method in one-to-many relationships
Parent Key Not Found Error
Querying tables with a one-to-many foreign key relationship
Hibernate - Force foreign key lookup on insert
Cascading non foreign key to Child Table
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013