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