-->
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: Using JPA just for auto-discovery, then native Hib...
PostPosted: Wed Jun 03, 2009 3:02 pm 
Newbie

Joined: Sat Aug 04, 2007 6:07 pm
Posts: 6
I would like to get the benefit of auto-discovery of my annotated classes by using JPA, but I'd prefer to continue using hibernate as usual (i.e. SessionFactory and HQL).

I have seen hints that I can simply configure a LocalContainerEntityManagerFactoryBean (in Spring) and then alias the session factory from getSessionFactory(). However this method doesn't seem to exist in those interfaces.

I see a more circuitous route where I get an entity manager's delegate and cast it to a SessionImplementor, but that doesn't feel right.

Is using JPA just to get auto-discovery a reasonable thing to do or do I just have to live with no auto-discovery of classes to use regular hibernate?

Why on earth hasn't somebody added whatever discovery code is used for JPA to the hibernate annotations core? Is use of native hibernate now discouraged? (Should I just move on?)


thanks,
Pat


Top
 Profile  
 
 Post subject: Re: Using JPA just for auto-discovery, then native Hib...
PostPosted: Thu Jun 04, 2009 1:00 am 
Newbie

Joined: Sat Aug 04, 2007 6:07 pm
Posts: 6
Well, the answer seems to be to blindly follow the hints I saw:

<bean id="sessionFactory" factory-bean="entityManagerFactory"
factory-method="getSessionFactory" />

But I still don't understand how that works, as that method doesn't seem to exist on the entity manager and the class doesn't seem to be proxied or intstrumented. There must be something I'm missing.


Pat


Top
 Profile  
 
 Post subject: Re: Using JPA just for auto-discovery, then native Hib...
PostPosted: Wed Jun 10, 2009 11:17 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

you just have to note that with hibernate as a JPA-Provider, the EntityManagerFactory (which is in fact an Interface) is an Instance of HibernateEntityManagerFactory - which is more or less a wrapper around a Session Factory. So you just do something like this:
Code:
   public static SessionFactory getSessionFactory(EntityManagerFactory emf) {
      if (emf == null) {
         return null;
      }
      HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
      return hemf.getSessionFactory();
   }


Top
 Profile  
 
 Post subject: Re: Using JPA just for auto-discovery, then native Hib...
PostPosted: Mon Jun 15, 2009 5:50 am 
Newbie

Joined: Tue Oct 16, 2007 5:45 pm
Posts: 4
Location: Poland
Could anyone explain me, how does the entityManagerFactory bean changes from org.springframework.orm.jpa.LocalEntityManagerFactoryBean to org.hibernate.ejb
Class EntityManagerFactoryImpl?


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.