-->
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: SessionFactory and entitymanager
PostPosted: Wed Jan 16, 2008 3:07 pm 
Newbie

Joined: Tue Nov 27, 2007 5:29 am
Posts: 9
I'm using Hibernate entitymanager together with wls10. Works great, entitymanager is created from META-INF/persistence.xml and so on.

Unfortunately (as according to spec) entitymanager injection/context is only available for certain types of classes(example beans,mdb's etc). Otherwise it is not available.

Now, I could use hibernate.session_factory_name property to bind hibernate sessionfactory into wls jndi tree. Again ,works great.

Now, I've got access to sessionfactory in my class inside the container. Is it now possible to get the entitymanager(factory)/Do I have to create new one (new EntityManagerImpl(...) or is this idea just stupid?


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Wed Jan 16, 2008 3:52 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
kakoni wrote:
Now, I've got access to sessionfactory in my class inside the container. Is it now possible to get the entitymanager(factory)/Do I have to create new one (new EntityManagerImpl(...) or is this idea just stupid?



To me if looks like if you can look up session factory you should be able to look up entity manager factory. What is your context? Where do you want to do this? Also read the whole way down this post and see if it puts you in any direction: http://forums.java.net/jive/thread.jspa?threadID=16808


Farzad-


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Wed Jan 16, 2008 4:12 pm 
Newbie

Joined: Tue Nov 27, 2007 5:29 am
Posts: 9
farzad wrote:
What is your context? Where do you want to do this


Hi!
within ejb3 context. I've got some utility classes(pojos) that need to access the entitymanager.


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Wed Jan 16, 2008 4:16 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
kakoni wrote:
farzad wrote:
What is your context? Where do you want to do this


Hi!
within ejb3 context. I've got some utility classes(pojos) that need to access the entitymanager.



Then I would assume those utility classes are used in some context of an ejb call then you would be able to add the resource ref in the ejb configuration file and have the utility class look up the entity manager factory. The url I sent before has some details on how to do this.

I hope this helps.

Farzad-


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Wed Jan 16, 2008 5:19 pm 
Newbie

Joined: Tue Nov 27, 2007 5:29 am
Posts: 9
farzad wrote:
kakoni wrote:
Then I would assume those utility classes are used in some context of an ejb call then you would be able to add the resource ref in the ejb configuration file and have the utility class look up the entity manager factory. The url I sent before has some details on how to do this.


Well no;) Sorry, perhaps I explained this bit wrongly;
Inside ear I've got classes for example commonj.timers. So they are not part of traditional ejb call.

Now my persistence.xml and entities have been part of the ejb.jar. I dont wether it would make a difference if I move them to the ear level (would that bind entitymanager(factory) to the jndi...)


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Thu Jan 24, 2008 6:27 am 
Newbie

Joined: Tue Nov 27, 2007 5:29 am
Posts: 9
Ok, this was in the documentation, funny how I didnt notice that in the beginning.

Quote:
The EJB3 specification defines a bootstrap procedure to access the EntityManagerFactory and the EntityManager. The bootstrap class is javax.persistence.Persistence, e.g.
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");


Top
 Profile  
 
 Post subject: Re: SessionFactory and entitymanager
PostPosted: Thu Jan 24, 2008 8:51 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
kakoni wrote:
Ok, this was in the documentation, funny how I didnt notice that in the beginning.

Quote:
The EJB3 specification defines a bootstrap procedure to access the EntityManagerFactory and the EntityManager. The bootstrap class is javax.persistence.Persistence, e.g.
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");


I heard somewhere this is best useful outside a container environment. I am not exactly sure what its side effects might be though.



Farzad-


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.