-->
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.  [ 3 posts ] 
Author Message
 Post subject: HELP! -> CascadeType.DELETE_ORPHAN -> BatchUpdateExcep
PostPosted: Wed May 23, 2007 6:05 am 
Newbie

Joined: Fri May 18, 2007 10:59 am
Posts: 3
I am getting a problem when removing an item from a OneToMany list. I can add users without any problem but cannot remove them. I am basically, removing a user from the list and doing saveOrUpdate(account).

My AccountDO has a list of UserDO as follows

@OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
@org.hibernate.annotations.Cascade( {
org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public List<UserDO> getUsers() {
return users;
}

I originally found that with only the CascadeType.ALL, there was no error but with the next load the deleted user came back again! I then found a FAQ about this and added the second annotation. This however causes the exception below after removing the user from the List. Have I interpreted the docs wrong?

Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`tenantchecker/tch_applicant_check`, CONSTRAINT `FK2028E125B7B27A4C` FOREIGN KEY (`user_id`) REFERENCES `tch_user` (`id`))
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 49 more

What should I do to enable me to remove a User from the List correctly?

Thanks in advance,
John


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 12:23 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Set the account to null from the user side as well.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 4:26 am 
Newbie

Joined: Fri May 18, 2007 10:59 am
Posts: 3
Yes that has solved it. Thanks.


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