Java Hibernate session delete of object

Posted by user2535201 on Stack Overflow See other posts from Stack Overflow or by user2535201
Published on 2013-06-29T19:31:57Z Indexed on 2013/06/29 22:22 UTC
Read the original article Hit count: 153

Filed under:
|

I'm really struggling with hibernate sessions, I never have the result I expect when making a query on a modified session object. I think all my problems are related. The last one is the following :

final Session iSession = AbstractDAO.getSessionFactory().openSession();
try {
    iSession.beginTransaction();
    MyObject iObject = DAOMyObject.getInstance().get(iSession,ObjectId);
    iObject.setQuantity(0); //previously the quantity was different from zero
    DAOMyObject.getInstance().update(iSession,iObject);
    DAOMyObject.getInstance().deleteObjectWithZeroQuantities(iSession);
    iSession.getTransaction().commit();
} catch (final Exception aException) {
    iSession.getTransaction().rollback();
    logger.error(aException.getMessage(), aException);
    throw aException;
} finally {
    iSession.close();
}

What I'm not getting is why the object is not deleted, since I'm modified it in the session, the query making the delete should find it. I had the same problem with creating an object with an incremental id in a session, then creating another one in the same session before the commit, with a select max(id)+1. But the session gets me the same number of id every time.

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate