-->
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 do I get the SessionFactory?
PostPosted: Tue Jan 03, 2012 2:56 pm 
Newbie

Joined: Fri Dec 23, 2011 7:40 pm
Posts: 12
I've tried:
Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();

and that results in a HibernateException /hibernate.cfg.xml not found.
Well, since the system is using a persistence.xml, that makes sense.

So, how am I supposed to get a Session Factory?


Top
 Profile  
 
 Post subject: Re: How do I get the SessionFactory?
PostPosted: Tue Jan 03, 2012 6:37 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 10:24 am
Posts: 25
I take it you're using JPA then? http://docs.jboss.org/hibernate/core/4. ... tstrapping


Top
 Profile  
 
 Post subject: Re: How do I get the SessionFactory?
PostPosted: Wed Jan 04, 2012 11:13 am 
Newbie

Joined: Fri Dec 23, 2011 7:40 pm
Posts: 12
Reading through that stuff again...
Okay, I'm guessing you mean I should set the hibernate.ejb.session_factory_observer property?
Hmm, that does look like it will do what I need. Hope it works.
Thanks.


Top
 Profile  
 
 Post subject: Re: How do I get the SessionFactory?
PostPosted: Wed Jan 04, 2012 11:33 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 10:24 am
Posts: 25
CasaDelGato wrote:
Reading through that stuff again...
Okay, I'm guessing you mean I should set the hibernate.ejb.session_factory_observer property?
Hmm, that does look like it will do what I need. Hope it works.
Thanks.

Actually I was referring to the top of the section (manager1 below is replaced with the name of your persistence unit in persistence.xml):
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");


If you really need access to the SessionFactory or Session after that you can use:
Code:
EntityManager em = emf.createEntityManager();
Session session = (Session)em.getDelegate();
SessionFactory sf = session.getSessionFactory();


But if you're using JPA, you should be using EntityManager and EntityManagerFactory.


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.