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: Cascade with Validation Error -> FK constraint violation
PostPosted: Tue Apr 09, 2013 9:48 am 
Newbie

Joined: Tue Apr 09, 2013 9:31 am
Posts: 2
I am faced with the following issue:

I have two classes (e.g. Parent and Child). When I am updating a Parent object, the Child object is created in the database by cascade, so the the Child object receives an Id. Now Hibernate attempts to update Parent and fails due to some validation error (say I didn't define a name for the Parent) -- The validation is performed by calling a Hibernate ClassValidator inside a class implementing PreUpdateEventListener.

I now have a Parent object, pointing to a Child object which has an Id even though its creation in the database was rolled-back due to the validation error of Parent.

If I then fix the validation issue and try to update Parent again, a Foreign-Key constraint violation exception is thrown as Hibernate thinks the Child object already exists in the DB (it has an Id after all).

I'd like to know if Hibernate provides an out-of-the-box solution to this scenario.

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Cascade with Validation Error -> FK constraint violation
PostPosted: Wed Apr 10, 2013 8:59 am 
Newbie

Joined: Wed Mar 13, 2013 11:32 am
Posts: 16
Hi

How are the releation between Parent and Child defined?

Br.

Jesper


Top
 Profile  
 
 Post subject: Re: Cascade with Validation Error -> FK constraint violation
PostPosted: Wed Apr 10, 2013 9:03 am 
Newbie

Joined: Tue Apr 09, 2013 9:31 am
Posts: 2
<many-to-one name="child" class="xxx.child" column="child_id" foreign-key="FK_PARENT_CHILD_ID" cascade="all" access="field"/>


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.