-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mixing JPA with HQL
PostPosted: Thu Dec 18, 2008 6:59 am 
Newbie

Joined: Tue Dec 16, 2008 8:56 am
Posts: 3
I have a configuration with JPA. Everything is fine and working.

When i use JPA syntax like this :

EntityManagerFactory emf = Persistence.createEntityManagerFactory("pmanager");
EntityManager em = emf.createEntityManager();
Query q = em.createQuery("from foo");
List l = q.getResultList();

OK! - Works.

But how do i have to do use Hibernate criteria, Query ?
How do i get a Hibernate Session Object ?
Or is this general a wrong approach ?

The reason for doing this is, that i like the annotaion concept from JPA,
but i want to use the power from HQL.

thanks for a code snippet

olaf


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 2:24 pm 
Newbie

Joined: Sat Aug 02, 2008 12:09 pm
Posts: 12
You can get the underlying session from em.getDelegate().
It will return an Object instance that you cast to Session.

Cheers

G


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 8:39 am 
Newbie

Joined: Tue Dec 16, 2008 8:56 am
Posts: 3
Thank´s !

EntityManagerFactory emf = Persistence.createEntityManagerFactory("pmanager");
EntityManager em = emf.createEntityManager();
Session session = (Session)em.getDelegate();

That´s what i was looking for...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.