-->
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: Understanding what "session.delete(objX)" means.
PostPosted: Thu Jun 02, 2005 9:31 am 
Newbie

Joined: Thu Jun 02, 2005 9:00 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0


Hi forum,

I'm currently evaluating hibernate, which appear to be a great tool !!
Thanks guyzz for it !!!!

Doing bqsic tests on simple objects, I realize the following :
Code:
  session.delete(objX);
  transaction.commit();

does delete correponding row in database (yeaahh!!!) but not in
memory ! List containing this object still refers to it ! (Knowing that this
list was built before the "delete" line using a query with createQuery(....)).

Manual says, section 10.8 :
Quote:
It's best to think of
Code:
delete()
as making a persistent
instance transient.

OK !For me, that's the reason.

My question : does anybody knows how to also remove the deleted
object from memory automatically, as I do not want to manage garbage
collection (I know , I know, too lazy) ?


Thanks in advance for your answers/suggestions/advisories/....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 10:01 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
Well, I guess you have to code it yourself. One solution is calling session.refresh(ObjY) for the objects with i.e. collection references to a deleted object. But it's neither convenient nor performant. A better way is to add remove()- functions for all collections which you must call after deletion.
Anyway, if you want a convenient manipulation of the objects where transient objects are updated automatically you need to add an extra layer above your generated Pojos. That how I do it.


Top
 Profile  
 
 Post subject: session.delete
PostPosted: Fri Jun 03, 2005 12:52 pm 
Newbie

Joined: Tue Mar 22, 2005 5:43 pm
Posts: 16
Location: Teksouth
session.delete(object) does delete record from database which was read before.

You can use other flavours like
session.delete("select * from tbl where id = 1")


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.