Hello, For an application, I am using Struts2, hibernate and spring for injection. Any time I save an object to DB, I HAVE to do inside the Serivces class(session injected here). In any action class, if i obtain current session and save it, it doesn't save the object to the database. Although, I do see insert into..... in the logs. why is that?
A:
I assume you are not doing transaction handling. You will not see a record in the database until the transaction is committed.
I guess Spring manages the transaction automatically in your service class. However if you use the session directly you also need to start/commit the transaction in your code.
See http://docs.jboss.org/hibernate/stable/core/reference/en/html/transactions.html for more details
Wolfgang
2010-08-11 18:05:01
You know what now that I think about it...Services class is annotated @Transactional, does that mean that for any code inside transaction will be handled, but if i do it outside of that class...i must commit transaction manually?
Nishant
2010-08-11 18:10:15
i see...thanks!
Nishant
2010-08-11 18:15:45