-->
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: Unable to delete child objects in a one-to-many case
PostPosted: Mon Jun 14, 2004 12:00 pm 
Newbie

Joined: Wed Jun 09, 2004 2:41 pm
Posts: 14
I have a the following one-to-many relation ship.

User-----------------(1...*) --------->UserRole

//User.hdb.xml
<hibernate-mapping package="com.beans">
<class name="User" table="USERS">
<id name="userId" column="USERNAME">
<generator class="assigned" />
</id>
<property name="password" column="USERPASS"/>
<property name="repId" column="SALESREPID"/>
<bag name="userroles" inverse="true" cascade="all">
<key column="USERNAME"/>
<one-to-many class="UserRole"/>
</bag>
</class>
</hibernate-mapping>

//UserRole.hbm.xml
<hibernate-mapping package="com.beans">
<class name="UserRole" table="USER_ROLES">
<id name="userId" column="USERNAME" unsaved-value="any">
<generator class="assigned"/>
</id>
<property name="roleName" column="ROLENAME"/>

</class>
</hibernate-mapping>

When I delete the the User object, it deletes only the user records, but not the user roles from the USER_ROLES.

Here are the POJOs:

public final class User implements Serializable {
private String userId;
private String password;
private String repId;
private List userroles;
....//and getters and setters
}

public final class UserRole implements Serializable {

private String userId;
private String roleName;

.......//and getters and setters
}

I do the following:

delete(User user) throws Exception
{
Session session = getSession();
session.delete(user);
session.flush();
session.close();
}

Do I need to explicitly call delete on on the child components?
Thanks,
Jeelani


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
remove inverse="true" since you don't have a bidirectional relationship.
You should chek the wiki page talking to inverse attribute, it is important to understand that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: The problem still exists
PostPosted: Mon Jun 14, 2004 3:32 pm 
Newbie

Joined: Wed Jun 09, 2004 2:41 pm
Posts: 14
I removed the inversion="true" to make it false (default value). Still I am not able to delete. Looking into the problems.

Thanks for the help.
Jeelani


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Oh
Code:
<class name="UserRole" table="USER_ROLES">
<id name="userId" column="USERNAME" unsaved-value="any">
<generator class="assigned"/>

means a user can have only 1 role.
If it is true, use a one-to-one
If it is false distinct the one-to-many key (USERNAME) from the rold id which must be unique.

_________________
Emmanuel


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.