I'm trying to implement a many-to-many association with data in the association class/table. I'm using a composite-element, but this doesn't allow many-to-many, so I'm using two many-to-ones, basing my config on the customer/order/product example in the reference documentation.
First problem: I can't figure out how to set/get data in the composite-element class (LineItem in the example, Pmask in my code). When I generate the Role, Moan, and Pmask classes with hbm2java, there's no mention of Pmask in Role or Moan, so I don't see how I can manipulate the Pmask instances.
Second problem: using my mappings, the schema is defined, but when I run the code below with the reflection optimiser turned off, I get
Code:
java.lang.IllegalArgumentException: object is not an instance of declaring class
...
at java.lang.reflect.Method.invoke(Method.java:324)
...
rethrown as net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling: object is not an instance of declaring class getter of com.spherion.ap.esb.auth.Pmask.mask
at tx.commit(). Running in the Eclipse debugger, it appears that method in Getter is defined as Pmask.getMask(), but the invoke target is the "role1" instance of Role, hence the exception. At this point I don't have a clue what's going on.
What am I doing wrong?
Code:
Code:
Role role1 = new Role("role1", 10);
ArrayList roles = new ArrayList();
roles.add(role1);
Moan root = new Moan();
Moan m1 = new Moan("child1", root);
m1.setRoles(roles);
Session session = sessions.openSession();
Transaction tx = null;
try
{
tx = session.beginTransaction();
session.save(root);
session.save(m1);
session.save(role1);
tx.commit();
session.close();
HBM files:
Code:
<hibernate-mapping>
<class name="com.spherion.ap.esb.auth.Moan" table="esb_moans">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" not-null="true"/>
<many-to-one name="parent" class="com.spherion.ap.esb.auth.Moan" column="parentid"/>
<list name="roles" table="esb_moans_roles" lazy="false">
<key column="moanid"/>
<index column="idx"/>
<composite-element class="com.spherion.ap.esb.auth.Pmask">
<property name="mask" type="long"/>
<many-to-one class="com.spherion.ap.esb.auth.Role" name="role" column="roleid"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.spherion.ap.esb.auth.Role" table="esb_roles">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" not-null="true"/>
<property name="rank" type="integer"/>
<list name="moans" table="esb_moans_roles" lazy="false" inverse="true">
<key column="roleid"/>
<index column="idx"/>
<composite-element class="com.spherion.ap.esb.auth.Pmask">
<property name="mask" type="long"/>
<many-to-one class="com.spherion.ap.esb.auth.Moan" name="role" column="moanid"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
Thanks.
PJDM