-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Forced Flushing
PostPosted: Fri Nov 21, 2008 5:34 pm 
Newbie

Joined: Mon Mar 17, 2008 3:51 pm
Posts: 8
Location: Colorado Springs, CO
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.