-->
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.  [ 4 posts ] 
Author Message
 Post subject: forcing hibernate to persist, how?
PostPosted: Tue Oct 17, 2006 12:39 pm 
Newbie

Joined: Wed Sep 07, 2005 8:22 am
Posts: 14
Hello all,

I've a simple question (I hope).

I have a EJB that stores serveral Tag objects.
This is done in a for loop, and at the end of each loop I make a call to my persist method.

The persist method is hidden behind a Delegate class.

Now the persist is done, but not each time around the loop.
All the Tag objects get persisted when the for loop finishes and the EJB ends.

Is there a way I can force/request that the persist of each Tag is done at the end of loop?

Thanks
Jeff Porter.



Hibernate version:
hibernate-3.0

Code between sessionFactory.openSession() and session.close():
Code:
      Session hsession = null;
      Transaction tx = null;
      try {
         
         hsession = factory.openSession();
         tx = hsession.beginTransaction();
      
         
         if (tag.getListOfTagRecords().size() > 0) {
            System.out.println("check");
         }
         hsession.saveOrUpdate(tag);
         
         hsession.flush();
           tx.commit();
      } catch (Exception e) {
         if (tx!=null) tx.rollback();
         throw new ApplicationException("Exception: " + e.getMessage(), e);
      } finally {
         hsession.close();
      }
      return tag;



Name and version of the database you are using:
MySQL

The generated SQL (show_sql=true):
MySQL Server 4.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 1:56 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Jeff,


You can call session.flush() to have Hibernate write to the database. Note that there are good reasons why hibernate implements transparent write behind.

A related issue is that if your transaction isolation level is set to REPEATABLE_READ other transactions are not supposed to see your changes until you close the transaction. This is a setting for both hibernate and the database, they are supposed to be in sync.

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 3:43 am 
Newbie

Joined: Wed Sep 07, 2005 8:22 am
Posts: 14
Hi mseritan,

I'm already calling session.flush().

Where would the transaction isolation level be set then?

jeff porter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 10:04 am 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Look for hibernate.connection.isolation here

http://www.hibernate.org/hib_docs/refer ... ation.html


Again, this is how databases are supposed to work. It involves hibernate, jdbc, driver, database.


Marius


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

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.