-->
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: Use EntityManager in J2EE server that doesn't support EJB3?
PostPosted: Wed May 03, 2006 7:35 pm 
Newbie

Joined: Wed Nov 02, 2005 5:20 pm
Posts: 9
Hi,

I am trying to use Hibernate EntityManager package in an old J2EE server which doesn't support EJB3 (Oracle's OC4J). Previously, I used Hibernate 3.1 Core in the J2EE server. I used Container Managed Transaction, org.hibernate.transaction.CMTTransactionFactory and sessionFactory.getCurrentSession() in order to get the session object associated with current transaction and also get the benefit of automatically flushing session before the transaction completes, closing session after the transaction completes.

However, I can’t find a method similar to sessionFactory.getCurrentSession() when I try to get an EntityManager when I use EntityManager package. Because this is old J2EE container that doesn’t support EJB3, the following annotation doesn’t work (em is always null):

public class SPDirectorySetupItemDAO {
@PersistenceContext(unitName="hibernate")
EntityManager em;


So I try to use following code to get EntityManager:

EntityManagerFactory emf=Persistence.createEntityManagerFactory("hibernate");

EntityManager em2 = emf.createEntityManager();


The J2EE server gives me following warning:
WARNING J2EE JTA0115 An exception occurred while making afterCompletion notifications: setRollbackOnly() called with no active Transaction

I don’t know whether this is correct way to get current EntityManager associated with current transaction.

Thanks a lot!

Jifeng


Hibernate version:
Core 3.2RC1 Hibernate Annotations 3.1.0 beta 10
Hibernate EntityManager 3.1.0 beta 8


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 3:43 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Check out this:
http://docs.jboss.org/ejb3/embedded/embedded.html

Quote:
JBoss EJB 3.0 supports an embeddable version that can be run outside of the application server in standalone applications, junit tests, Tomcat, or even other non-jboss application servers. The full JBoss JEMS suite is not all embeddable yet, but here's what is available.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 10:02 am 
Newbie

Joined: Wed Nov 02, 2005 5:20 pm
Posts: 9
I can't use JBoss EJB Embaddable container in my company's production environment for following reasons:

1. JBoss EJB Embaddable container is in alpha version. It is not reliable enough for a production environment.

2. I don't want to 2 EJB containers ( the other one is Oracle's) running in our system. It makes source code hard to maintain and to communicate with each other.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 3:32 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
2. I don't want to 2 EJB containers ( the other one is Oracle's) running in our system. It makes source code hard to maintain and to communicate with each other.


Then just use Hibernate persistence and still Oracke's EJBs:
Code:
    <persistence-unit name="punit">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>



Or you can still fall back to H3 SessionFactory.getCurrentSession(), which is even better than EJB3 persistence - Criteria API, ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what is the full oracle stacktrace?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 11:05 am 
Newbie

Joined: Wed Nov 02, 2005 5:20 pm
Posts: 9
The Exception I mentioned is gone after I use CurrentEntityManagerImpl in EntityManagerFactory.getEntityManager() method.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 12:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
EntityManagerFactory.getEntityManager()

is nolonger part of the specification, because of... Oracle I believe :-)

_________________
Emmanuel


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.