-->
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: Some Thoughts about remove()
PostPosted: Wed May 28, 2008 10:57 am 
Regular
Regular

Joined: Wed Apr 09, 2008 10:28 am
Posts: 52
hi,

last couple of days i've read a lot of articel and tutorials mostly about generic dao's. i've reconized that mostly the remove method gets as parameter an persistent Object. Wouldn't it be better to use as parameter the primary key so when actually remove is called you can do something like this:

Code:
em.remove(em.find(pk));


the gain by this is that you don't have to worry about running into a detached objects exception when you perform a find and right after a remove without reattaching the object to the session.

I had a lot trouble about this detached object exception when i did call find from an action and tried to use a remove right after it for e.g

Code:
user = service.find(id);
service.remove(user);


the background is that somehow the shared entitymanager i'm using opens a session when doing find(not entirly sure about that actualy) and closes it right after so user gets detached. Maybe there are some other ways or thought which you could share with me on this issue.
But i don't really see some disadvantage by using the remove method like i said except that you will do one more operation within a transaction if i'm not entirly wrong.

Maybe there is even a way to somehow let user assign to a session again but i don't really know how to do that with an shared entity manager cause u cant use something like this with it
Code:
em.getTransaction() ...


These are just some thoughts from me i'm still new to this stuff so some things here might be wrong or do not make any sense still i want to discuss about it and i hope i'm on the right place here.

regards

kukudas


Top
 Profile  
 
 Post subject: Re: Some Thoughts about remove()
PostPosted: Wed May 28, 2008 12:47 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Why should one load an entity and remove it from session if it is not present in L1 cache? To me handling the exception is a lot more efficient.



Farzad-


edit: please ignore this. I confused remove with evict...


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.