-->
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.  [ 7 posts ] 
Author Message
 Post subject: EntityManagerFactory -> EntityManager -> EntityTransac
PostPosted: Thu Sep 28, 2006 7:41 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
Hello,

We are currently designing the Transaction and Concurrency Handling of our application and have a few questions concerning Hibernate Transaction and Session Handling. We have read all the documentation about Transactions and Concurrency and have a few questions:

We are generally talking about Hibernate 3.2 (EJB3.0) and J2SE.
    - We have a EntityManagerFactory which holds a Connection Pool for our Database.

    - If we need a Persistent Context, we fetch an EntityManager from our EntityManagerFactory. This means, simple expressed, we get a connection to our database from our connection pool.

    - We want to do something. For this we open a transaction for the current EntityManager with EntityManager.getTransaction(). Now we have an open transaction. We have always only one opened transaction for one EntityManager.

    - If we close the Transaction and the EntityManager, the connection is returned to our connection pool to make it available for the next EntityManager.

Could someone please confirm the above described procedure? It is very essential for me to understand the concepts of Hibernate's Transaction Handling.

Regards,

Christoph.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The connection is not retrieved until the EM actually needs it, this is not at EM creation time.
you can have multiple resource-local Tx per EM, but only one at the same time
When the tx is commited or orllbacked, the connection is released.


But once again, JTA/EJB 3 is a nicer concept and works on SE

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 1:00 pm 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
emmanuel wrote:
When the tx is commited or orllbacked, the connection is released.

does that mean the connection is put back to the connection pool or is the connection closed? I am very petty because creating db-connections is very expensive.

thx.
chistoph.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
I am very petty because creating db-connections is very expensive.


It's not. That's why you have a connection pool.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 6:23 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
JTA really works in a J2SE environment? I think it would be the best solution to use JTA, but I can't find good documentation on it.

It is activated with the hibernate.transaction.factory_class property. But I can't find any docu how to use it, perhaps someone has good resources about using JTA with J2SE.

Regards,

Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 11:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
JBoss Embeddable EJB3

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 01, 2006 5:57 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
Isn't JTA and JNDI available without Embedded EJB3 for J2SE?

When I set
Code:
hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup

and I make a new EntityManagerFactory
Code:
EntityManagerFactory factory = configuration.createEntityManagerFactory();

I get a NoInitialContextException. Should it run on a J2SE or really do I need Embedded EJB3?

Regards.


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