Wednesday, April 8, 2009

Attaching detached objects

Iam reading a list and processing each element.
For example I get list of Memberships. Each Membership has a user. Each User has an Address.
If I get list of Memberships in one session. Then try to access address from the user in another session we will get the famous 'no session exception'
We need to attach the user created in the first session to the second one.

session2.update(user);
system.out.printf("user City :"+ user.address().getCity);
so session1 creates memberships.
user.address is invoked by session2.
before we invoke the command, we need to attach user to the session2.
session2.update(user) will do the trick.

No comments:

Post a Comment