-->
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: HQL delete not working with non-cascading many-to-many
PostPosted: Wed Jul 25, 2007 3:19 pm 
Newbie

Joined: Tue Mar 06, 2007 1:35 pm
Posts: 10
Hi guys. I'm using hibernate 3.2.4.sp1 with Informix 10.

I have an Obj1 that has a many-to-many mapping with a domain Obj2 object and a one-to-one mapping with an object Obj3. Both Obj2 and Obj3 shouldn't be touched when Obj1 gets deleted. Alright...

Having the delete HQL delete Obj1 obj1 where obj1.obj3.id = :id being executed like the following:
Code:
Query q = session.createQuery( "delete Obj1 obj1 where obj1.obj3.id = :id" );
q.setParameter( "id", id );
return q.executeUpdate();

I receive the exception:
org.hibernate.exception.ConstraintViolationException: could not execute update query
and the following log line:
16:05:50,892 ERROR [JDBCExceptionReporter] Key value for constraint (u135_69) is still being referenced.

Looking at the generated SQL, I see that Hibernate is trying to delete the only the records of the main object, leaving behind the many-to-many associative table, like this:
Code:
    delete
    from
        Object1
    where
        obj3_id=?


When I first execute a selectec and then a delete for each returned instance, everything works. Any idea?

TIA!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 9:21 am 
Newbie

Joined: Tue Mar 06, 2007 1:35 pm
Posts: 10
Anyone? That problem is really bugging me...


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.