-->
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: How to use JPA + JTA without EJB container correctly?
PostPosted: Thu Jan 14, 2010 7:31 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Preliminary: Why use JTA instead to use JdbcTransactionFactory if working without EJB container?
Answer: If you want to use JBosscache or Infinispan as 2LCache impl. then you must use JTA.

If configuring hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
then following warning comes out when creating the Enititymangerfactory (version 3.4):
Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation
If removing hibernate.transaction.factory_class property from persistence.xml (leaving persistence-unit transaction-type="JTA"),
then Ejb3Configuration automatically sets JoinableCMTTransactionFactory which is not correct, because I not use any EJB container.

Furthermore Ejb3Configuration gives following warning
Defining hibernate.transaction.flush_before_completion=true ignored in HEM
and overrides it's value to false.

As I use programmatic transaction demarcation using the javax.transaction.UserTransaction api
and using emf.createEntityManager() to interact with persistent objects,
this has the consequence that I must manually flush each time before I perform a commit!
This goes clearly against documentation in the book 'Java Persistence with Hibernate' !

After all the community using JPA with JTA outside any EJB-container might be small,
but with newer hibernate releases this group seems to be left to one's own devices, sob !


Top
 Profile  
 
 Post subject: Re: How to use JPA + JTA without EJB container correctly?
PostPosted: Mon Jan 18, 2010 9:34 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Here's the official description of hibernate.transaction.flush_before_completion

Code:
hibernate.transaction.flush_before_completion     
If enabled, the session will be automatically flushed during the before completion phase of the transaction.
Built-in and automatic session context management is preferred, see Section 2.5, “Contextual sessions”.

e.g. true | false


The sentence "Built-in and automatic session context management is preferred" is rather confusing!
What means 'preferred' exactly in this context ?!
Does is mean that 'Programmatic transaction demarcation' has become obsolete or a 'anti-pattern'?
Why is hibernate.transaction.flush_before_completion automatically set to false
if using the Enititymanger ?

Anyway following code-lines in org.hibernate.ejb.Ejb3Configuration#prepareProperties(Properties properties, Map workingVars)
are responsible for the described trouble:

Code:
if ( hasTxStrategy ) {
         log.warn(
               "Overriding {} is dangerous, this might break the EJB3 specification implementation",
               Environment.TRANSACTION_STRATEGY
         );
      }
      if ( preparedProperties.getProperty( Environment.FLUSH_BEFORE_COMPLETION ).equals( "true" ) ) {
         preparedProperties.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "false" );
         log.warn( "Defining {}=true ignored in HEM", Environment.FLUSH_BEFORE_COMPLETION );
      }


On page 446 of the book 'Java persistence with Hiberante' there's described:
... on the other hand, you can enable the hibernate.transaction.flush_before_completion ... configuration options an let Hibernate take care of this for you again.


Top
 Profile  
 
 Post subject: Re: How to use JPA + JTA without EJB container correctly?
PostPosted: Wed Jul 07, 2010 11:31 am 
Beginner
Beginner

Joined: Wed Nov 10, 2004 5:48 pm
Posts: 32
Location: Portland
We are having this exact same problem. There seems to be no way to get flush on completion working with tomcat+JTA. Did you find a solution?


Top
 Profile  
 
 Post subject: Re: How to use JPA + JTA without EJB container correctly?
PostPosted: Thu Jul 08, 2010 2:04 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
At that time I tried to get in contact with Emmanuel Bernard,
he is the main developer or hibernate-entity-manager, but unfortunately I got no feedback from him.

>>Did you find a solution?

I do manually flush each time before I perform a commit


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.