-->
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.  [ 4 posts ] 
Author Message
 Post subject: Parent Saves But Child Does Not
PostPosted: Thu Sep 15, 2005 4:51 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 5:08 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
try

<set name="authoritieses" inverse="true" cascade="save-update">
<key>
<column name="username" length="50" not-null="true" />
</key>
<one-to-many class="com.matt.Authorities" />
</set>


Top
 Profile  
 
 Post subject: Parent Saves But Child Does Not
PostPosted: Thu Sep 15, 2005 9:23 pm 
Newbie

Joined: Wed Sep 14, 2005 9:15 am
Posts: 12
Location: St. Louis
Yep, that did it! Setting the cascade="save-update" did the trick! Thanks a ton for your response, I more than appreciate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 10:20 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
so how bout a credit? :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.