-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Parent Saves But Child Does Not
PostPosted: Thu Sep 15, 2005 4:46 pm 
Newbie

Joined: Wed Sep 14, 2005 9:15 am
Posts: 12
Location: St. Louis
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:32 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I think you just need to set the cascade attribute in the parent mapping file.

See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#example-parentchild-cascades

Saving the parent doesn't cause the child to save, by default. You have to tell Hibernate that you want that behavior, with the cascade attribute.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.