Hibernate version: 3.2
Name and version of the database you are using: PostgreSQL 8.3
Hi, I'm a Hibernate newbie and I was hoping to find some explanation or at least direction regarding some behavior I've been seeing recently in my project.
I've been running the following code:
Code:
public T makePersistent(T entity) {
Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(entity);
tx.commit();
session.close();
return entity;
}
It's basically from a DAO pattern that's typed (T) to a certain persistable hibernate entity. So when I run this code using a hibernate.cfg.xml and as an application from my debugger, the entity IS persisted in the DB.
However, when I move it all to the server side (JBoss 4.23GA)and deploy it all as a HAR, the object is NOT persisted. No exception is thrown either. If I explicitly flush the session by adding session.flush() right before I close the session, then it does appear in the DB... Also, if I force the session to use FlushMode.COMMIT, the object still is not persisted upon committing the transaction.
So here are my thoughts/questions.
1) Perhaps Hibernate is caching something when I happen to be running on the server side. If so, does flush force the data to move from the cache to the DB?
2) I thought I'd read in Java Persistence w/ Hibernate that the default behavior of a session is that the flush mode is FlushMode.AUTOMATIC meaning that whenever a Transaction's commit method is called, flush is also called (in favor of preventing stale data in resulting queries). This seems not to be happening in this case which is really confusing me. In fact, it seems that no matter which mode I set, things are only sent to the DB when I explicitly flush the session.
Any help would be greatly appreciated as it's obvious that I'm not understanding something. The more I think about it maybe I'm just butchering Sessions and Transactions. Sigh.
Thanks.