-->
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: Deleting Objects Proxies results in SELECT statement
PostPosted: Tue Jan 18, 2005 11:45 pm 
Newbie

Joined: Fri Jan 07, 2005 3:34 pm
Posts: 8
Hibernate version:
2.1.7c

When I do:

MyClass obj =(MyClass)so.session.load(MyClass.class,new Long(id));
session.delete(obj);

it still results in a select, and then a delete statement. If MyClass is proxied shouldn't it not have a select statement since the delete (should) only require the identifier column.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 2:58 am 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Depends. You can set a class mapping to perform a "select-before=update," which in a highly concurrent environment is advantageous. It is very possible, for example, that another user in another application could have deleted the object in question. If the delete occurs outside the current Hibernate session, there's no way Hibernate can know that the delete occurs. So, Hibernate must do a check to verify that the object exists before it issues the delete.

Take a look at the select-before-update documentation in:
http://www.hibernate.org/hib_docs/refer ... tion-class

Also, your object could be in a detached state. If that's the case, I believe deleting the object will cause its persistent state to be updated from the database (translation: a select to the DB). I'm not 100% on this, so experimentation may be in order. Check out section 4.2.6 in Hibernate in Action for more information. If this is the case, then examine why your object is detached in the first place. Did you intend for the object to be detached? Could you use a ThreadLocal/Open Session In View pattern to keep the sesion open, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 4:55 pm 
Newbie

Joined: Fri Jan 07, 2005 3:34 pm
Posts: 8
Hmm, well basically the solution I'm going to do is to have to write a custom delete(query) that uses my lazy object that only gets the PK, and thus does not require a load. It just seems to me that a delete(object) where object is lazy, should not require a select.

The concurrency problem you suggested is solved by changing the transaction level isolation. Adding extra selects doesn't help.


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.