-->
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: Basic understanding of JPQL and HQL
PostPosted: Mon Jan 31, 2011 1:00 pm 
Newbie

Joined: Mon Jan 31, 2011 12:54 pm
Posts: 2
Dear all,

I am a beginner with Hibernate and JPA.

I have a basic question regarding HQL and JPQL.

I might be using EJB 3.x, JPA and Hibernate for next project.

I ran some samples with EJB 3.x JPA with Hibenate as ORM framework.

My question is whether we have to use JPQL or HQL or both in entity classes and hibernate files?. If both are needed why both?

Is that something JPQL can do that HQL cannot do and vice versa. Is one better over other?

Thanks in Advance and Appreciate your inputs.


Best Regards

Harish


Top
 Profile  
 
 Post subject: Re: Basic understanding of JPQL and HQL
PostPosted: Mon Jan 31, 2011 5:59 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Just to make sure you know that: JPA is a specification on how to do OR-Mapping. Hibernate is one implementation of it, so it offers all JPA-features plus a some more useful features. So JPQL is also a specification on how to query objects, HQL is a kind of implementation.

Actually, when using Hibernate as ORM-Tool you will never feel there is a difference between JPQL and HQL. I have to admit that at this moment, I do not even know a big difference. I guess HQL gives you a few more features as hibernate offers more features than the JPA standard.

So don't worry about this, just start using hibernate while you read through the reference guide.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Basic understanding of JPQL and HQL
PostPosted: Mon Jan 31, 2011 10:29 pm 
Newbie

Joined: Mon Jan 31, 2011 12:54 pm
Posts: 2
Thanks Merder. It was a good and relevant answer. Both JPA and JPQL are specifications and Hibernate and HQL are popular implementations.
It will help me in Hibernate and HQL world.

I have another related question

Can HQL queries be written in hibernate mapping xml file only or they can be embedded in Entity POJO classes as well?

Can persistence.xml contain HQL queries in JEE application?

Kindly let me know.

Thanks in Advance

Harish


Top
 Profile  
 
 Post subject: Re: Basic understanding of JPQL and HQL
PostPosted: Thu Feb 10, 2011 3:27 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Yes, you can include queries in your entities using annotations: http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-query-hql

I would not map my queries in persistence.xml, but either use annotations or seperate mapping files, which are listed in persistence.xml.

_________________
-----------------
Need advanced help? http://www.viada.eu


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.