-->
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: Application managed EntityMananger
PostPosted: Wed Sep 10, 2008 11:18 am 
Newbie

Joined: Wed Sep 10, 2008 9:43 am
Posts: 4
Hi,

I'm working on a EJB 3.0 + Hibernate project.
I've decided to use an application managed EntityManager instead of a container managed EntityManagaer.

I'm creating the EntityManager using an EntityManagerFactory and in another class, I'm using @PersistenceUnit(name="myName") to try and inject the EntityManager I've created into an EntityManager class member (The persistence unit is defined in persistence.xml).

The problem is that the injection doesn't work and I get a null value.

I'm assuming that I can use entity injection by using @PersistenceUnit even without a container?
Any ideas what I'm doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 5:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I believe @PersistenceUnit injection should work as well, but this is really a question specific to the container you are using.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 6:14 am 
Newbie

Joined: Wed Sep 10, 2008 9:43 am
Posts: 4
Hi,

I stated in my original message that it's an application managed EntityManager and that I wasn't using a container.....

Is @PersistenceUnit only supported within a container?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 9:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

@PersistenceUnit is still an annotation 'consumed' by the container. The difference is that @PersistenceUnit gives the developer more control over the entity manager regarding creation and deletion. Using @PersistenceContext the container will be responsible for the life cycle of the entity manager.

--Hardy


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.