-->
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.  [ 6 posts ] 
Author Message
 Post subject: Flushing Session by CMT
PostPosted: Tue Apr 04, 2006 7:34 am 
Newbie

Joined: Mon Feb 27, 2006 2:58 am
Posts: 10
Hibernate version: 3.1.2

My Config:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.session_factory_name">fcbk_hibernate_SessionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.jndi.url">t3://localhost:7001</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.connection.datasource">resolveDataSource</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="show_sql">true</property>
<property name="transaction.flush_before_completion">true</property>

</session-factory>
</hibernate-configuration>

Question:

Am using EJB2 Session Bean for Transaction Mgmt with WebLogic Server 8.1 Sp3, and I'm not using any Transaction statements in my Hibernate Code.Also am using sessionFactory.openSession() not getCurrentSession() .In this case when I use any DMLs like update(), save() or delete() in session...data is not flushed to DB, unless I do session.flush() explicitly..But CMT is taking care of all rollbacks, happening at the time of RunTimeExceptions, even if I use session.flush().


My Question is will CMT won't control the flushing of session data into DB by itself?
Even I've tried with setting <property name="transaction.flush_before_completion">true</property> in Cfg.
My Code snippet:
public void deleteLocation(Long locationId){
logger.debug("deleteLocation: receiving locationId = " + locationId);
Session session = null;
try {
session=(Session)getSession();
Location location = (Location)session.load(Location.class, locationId);
session.delete(location);
//session.flush();
} catch(HibernateServiceLocatorException ex) {
logger.error("deleteLocation:: caught a SQLException. Will continue", ex);
throw new FCBKException("DeleteLocationError","Could not Delete Location.", ex);
} finally {
if(session.isOpen()) {
session.close();
}
}
logger.debug("deleteLocation:: exit");
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 7:58 am 
Beginner
Beginner

Joined: Tue May 09, 2006 2:30 am
Posts: 22
Hi !

I have exactly the same issue in my own project.
Did you find a way to resolve this ?

thanks

_________________
--
Celine


Top
 Profile  
 
 Post subject: Flush the session explicitly
PostPosted: Tue May 30, 2006 8:27 am 
Newbie

Joined: Mon Feb 27, 2006 2:58 am
Posts: 10
Linoux wrote:
Hi !

I have exactly the same issue in my own project.
Did you find a way to resolve this ?

thanks


In this scenario, hibernate session is not a contextual session (http://www.hibernate.org/hib_docs/v3/api/org/hibernate/context/CurrentSessionContext.html) in sense the session is not associated with the CMT.Both session and EJB's Transaction act independently each other.Here, Session serves as just a cache and JDBC connection, since from sessionfactory we are opening new connection everytime.So we have to explicitly flush the session using session.flush().It is inevitable with sessionFactory.openSession().Because EJB won't flush the session, since it is not controling the session.So we have to flush(in simple terms, move the objects in cache to BD thru SQLs) explicitly.

To avoid explicit flushing of session, use sessionFactory.getCurrentSession(), which will open a new session and bind for a JTA and give you same session within that transaction.plz refer http://hibernate.org/42.html#A7.In this case when the system transaction commits (the EJB transaction completes), the Session is automatically flushed and closed.

Problem: sessionFactory.openSession()
Solution: sessionFactory.getCurrentSession()

Hope this would help you to fix the issue.else ping me at athiganesh@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 10:44 am 
Beginner
Beginner

Joined: Tue May 09, 2006 2:30 am
Posts: 22
Hum, I'm affraid using SessionFactory.getCurrentSession() instead of SessionFactory.openSession() does not solve my problem : my persistent objects are stil not stored in DB... Except if I explicitly flush the session before the CMT commit...

_________________
--
Celine


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
We would need to see some logs (debug level) showing (1) the SF startup config and (2) the processing during this code snippet.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 7:41 am 
Beginner
Beginner

Joined: Tue May 09, 2006 2:30 am
Posts: 22
Thanks, but I think I solve this problem finally...

But I still have a question for you if you don't mind !

Does hibernate allow several transactions to run in the same session ? If yes how do you make it work in CMT ? My objective is to run a procedure like this :

1. Make a big query outside a transaction
2. iterate the query results and process each inside a transaction

All these operations must be done in the same hibernate session, else I will have to merge the entities returned by my query into each transaction's session, and it will take too much time !

I hope I've been clar enough, thanks for your responce !

_________________
--
Celine


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.