I seem to be having issues saving child records when calling the saveOrUpdate method. The parent record saves perfectly, however, the child record refuses to save. In addition, no errors appear in the log.
Here are the .hbm docs:
PARENT:
<hibernate-mapping>
<class name="com.matt.Users" table="users" catalog="matt">
<id name="username" type="string">
<column name="username" length="50" />
<generator class="assigned" />
</id>
<property name="password" type="string">
<column name="password" length="50" not-null="true" />
</property>
<property name="enabled" type="boolean">
<column name="enabled" not-null="true" />
</property>
<set name="authoritieses" inverse="true">
<key>
<column name="username" length="50" not-null="true" />
</key>
<one-to-many class="com.matt.Authorities" />
</set>
</class>
</hibernate-mapping>
CHILD
<hibernate-mapping>
<class name="com.matt.Authorities" table="authorities" catalog="matt">
<composite-id name="id" class="com.matt.AuthoritiesId">
<key-property name="username" type="string">
<column name="username" length="50" />
</key-property>
<key-property name="authority" type="string">
<column name="authority" length="50" />
</key-property>
</composite-id>
<many-to-one name="users" class="com.matt.Users" update="false" insert="false">
<column name="username" length="50" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
JAVA CODE:
Users user = new Users();
user.setUsername("matt");
user.setPassword("password");
user.setEnabled(new Boolean(true));
AuthoritiesId authoritiesId = new AuthoritiesId();
authoritiesId.setUsername("matt");
authoritiesId.setAuthority("ROLE_USER");
Authorities authorities = new Authorities(authoritiesId);
Set mySet = new HashSet();
mySet.add(authorities);
user.setAuthoritieses(mySet);
session.saveOrUpdate(user);
I'm guessing there's something wrong with my hbm docs, but I just cannot figure out what's wrong...
Any help is greatly appreciated!
Thanks,
Matt
|