Reputation: 2591
I am using hibernate to connect to a mysql database.
My saveOrUpdate method is :
public void saveOrUpdate(T t){
Session session = HibernateUtil.getSession();
Transaction transaction = session.beginTransaction();
session.saveOrUpdate(t);
transaction.commit();
}
I used this method actually for about half year, it worked well. But now when I do junit test using this method, it seems suck. I do saveOrUpdate first and then use Criteria to query, it gets the result seems to be right, but in database nothing actually changed.
Could anyone please give me any hint about what's happening here?
Thank you very much.
Upvotes: 0
Views: 199
Reputation: 1595
What is your JUnit configuration set to for transactions? I believe it is set to rollback all the transactions in the test. It should rightly be so, as after a test the database should be put back into a consistent/known state. The correctness of your code should rely on how you write the test and not the records being physically present in the database.
Upvotes: 1