-->
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.  [ 1 post ] 
Author Message
 Post subject: Question on SQL statements generated by Hibernate.
PostPosted: Wed Nov 19, 2008 6:05 am 
Newbie

Joined: Thu Oct 02, 2008 6:46 am
Posts: 5
I have a unidirectional many-to-many mapping between Person and Address (see example 7.3.4 of the Hibernate Reference Documentation 3.2.2).

The following code

Code:
Person person = new Person();
session.save(person);
session.delete(person);


results in:

Code:
Hibernate: insert into Person default values
Hibernate: delete from Person where personId=?


Adding a refresh:

Code:
Person person = new Person();
session.save(person);
session.refresh(person);
session.delete(person);


gives:

Code:
Hibernate: insert into Person default values
Hibernate: select person0_.personId as personId0_0_ from Person person0_ where person0_.personId=?
Hibernate: delete from PersonAddress where personId=?
Hibernate: delete from Person where personId=?


This is more or less the problem that I face in a real-world application. A user can select objects to be deleted from a list. For (lazy) objects that were already persistent, extra delete statements are generated, but for newly created objects, only the corresponding row in the Person table is deleted.

Can somebody explain me why Hibernate behaves this way? Is there a way to have delete statements for association tables at all times?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.