Skip to main content

Remove an object from session in hibernate



How can I remove an object from hibernate session? In my code I am fetching one list from the DB and searching if the user entered data is already there in the DB. If it is there I am overwriting it. Else I am creating a new object and saving it. But the jboss shows error that there are two objects in session. As far as i guess one object is the object that iterates through the list and other is the one newly created for saving the data.







for(Allocation al: allocatelist){

if(al.getDate().compareTo(dt)==0){

al.setAllocated(gpsz);

getManager().save(al);

flag=1;

break;

{

{







If the above condition fails then am creating and new object and saving it. So is there any way by which I can remove this object "al"? I don't have merger or update methods I have tried "evict()" also but its of no use. The else block







Allocation allocate = new Allocation();

allocate = filldata(allocate, dataMap,i);

getManager().save(allocate);

filldata() fills the inputs into the object.`




Comments

  1. If the Allocation object is managed by Hibernate, then there is no need for you to call getManager().save(al), because hibernate detects that the object is changed and it will automatically update the database.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?