-->
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.  [ 9 posts ] 
Author Message
 Post subject: Session is not flushed
PostPosted: Mon Sep 05, 2005 2:31 am 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
I have the following code to use Hibernate with JTA

Code:
UserTransaction utx = ServiceLocator.getInstance().getUserTransaction();
utx.begin();
Session session = sessionFactory.openSession();
session.save(new Employee("1", "Fred", "Flintstone");
utx.commit();
session.close();


The Hibernate configuration is as follows,

Code:
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.auto_import">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
<prop key="hibernate.query.substitutions">true=1,false=0</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.max_fetch_depth">10</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<prop key="hibernate.connection.release_mode">after_statement</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="jta.UserTransaction">javax/transaction/UserTransaction</prop>
<prop key="hibernate.connection.datasource">dataSource</prop>


However, the object is not saved when the transaction is committed. The only way I can it working is to do an explicit flush. Is there anyway I can get Hibernate to automatically flush when the JTA transaction commits. I have been trying to use work arounds with transaction synchronization registration. I was wondering whether there was any simpler solution. I use Hibernate 3.0.

Any help would be highly appreciated.

Ta
Abu Mariam


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 2:52 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Try following code:

Transaction trans=hsession.beginTransaction();
hsession.save(<urobject>);
trans.commit();

This would save ur transaction!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 3:27 am 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
Thanks for the reply. However, I would prefer to use JTA user transaction explicitly rather than getting the Hibernate transaction API to use JTA.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 3:48 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
My JTA knowledge may be a little thin, but don’t you have to complete the session before you commit your transaction?

If anything went wrong with the session, even the close, you would rollback the transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 4:17 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
With Hibernate, you have to use JDBCTransactionFactory if you decide to use Hibernate in non-managed environment (without app server), else JTA (if u have app server that is capable of managing JTA).


Dont know if you can use UserTransaction (or JTA Transaction) provided by API though Hibernate Transaction is a descendant of it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 4:20 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Take a look at the following lines of information:


The UserTransaction is not available to the following components:
CMT enterprise beans. Any attempt by such beans to obtain the interface results in an exception in accordance with the EJB specification.


-------------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 4:24 am 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
I am not using EJBs at all. It is just a J2EE web application with JTA for transaction demarcation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 4:27 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
WHAT IS UR APP SERVER??

IF you dont use APP SERVER, what is ur web server???

Important thing you have to pay attention to is, if your application is MANAGED or NOT!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 6:20 am 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
I am using Weblogic server. As a last ditch effort I added code to lookup the TransactionManager and register a Synchronization callback with the current Transaction when the Hibernate session is opened, so that I can do a flush in beforeCompletion. For some reason, Weblogic is not calling beforeCompletion.


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