Team,
I have some code like this
Code:
method{
do{t = session.transaction;
try{
t.begintransaction
----code----
VO p = new VO();
session.save(p); // db insert not yet called
---code---
t.comit;
}catch{
t.rollback;
}
}
}//method end
ID is generated by a custom class that i have built which basically reads a database table for id and updates the same at the same time.
Now the above does not work as the t.rollback does not rollback the saved object. Moreover the next call to flush still inerts the Object as the tx.rollback is just a sql level rollback and not object level.
To correct that i did this and it worked beutifully, meaning that the object was not inserted when session.flush was called next time at some other place in the code.
Code:
method{
do{t = session.transaction;
try{
t.begintransaction
----code----
VO p = new VO();
session.save(p); // db insert not yet called
session.flush(); // db insert forced.
---code---
t.comit;
}catch{
t.rollback;
}
}
}//method end
The above code did the real rollback as needed.
However the next time it comes to this method the same id is got from the db as it is available and the error says that "id already asssociated with session". So i did this.
Code:
method{
do{t = session.transaction;
try{
t.begintransaction
----code----
VO p = new VO();
session.save(p); // db insert not yet called
session.flush(); // db insert forced.
session.evict(p) // forced remove from session
---code---
t.comit;
}catch{
t.rollback;
}
}
}//method end
Still i get the same error "id already asssociated with session".
Any clues..
Suchak Jani