Hello,
I have a strange issue and I do not find the right query to google for.
following situation - ORACLE Database - Sequences as ID generator.
Record "OrderHeader" contains a Set of "OrderLines" as childs.
While saving the header object, all lines were updated to the database to, I do not need to save the lines. (thats great!)
Now I have a new header record, containing some lines.
I use "getSession().saveOrUpdate(order);" to save the header record including the lines.
The header could be saved by the database.
But while saving one line, the database runs to an exception (in the current case, a not null field was null)
In my code, I do a rollback after that.
That means, the header object does not exists anylonger in the database.
But since the database needed to insert the header to the table in order to beeing able to insert the lines in the table, I seems that the header object is marked as persistent.
If I run the code "getSession().saveOrUpdate(order);" I get no exception again, because the hibernate believes, the object is persistent. But that is not right, due to the rollback, the object is not persistent.
My Question:
what can be done, in order to mark the object as transient, after the rollback.
Here is some type of code I have:
Code:
public boolean saveOrder(PurOrderHeader order) {
PurchaseOrderDao orderDao = new PurchaseOrderDao();
try {
orderDao.setSession(em.getSession());
em.begin();
orderDao.saveOrder(order);
em.commit();
} catch (Exception e) {
em.rollback();
log.error("Failed to save purchase order.", e);
return false;
}
return true;
}
/// and the dao:
public void saveOrder(PurOrderHeader order) {
getSession().saveOrUpdate(order);
}
After the rollback, my new object has got an Id (generated by the sequence), even if I set this to null back, the object seems to not be saved. My only explaination to that is: The hibernate believes that the header object is persistent and so it believes there is either nothing to be done or it can do an update.
Best Regards
and thank you for your assistance
Alexander