Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Query and HQL

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am quiet new to Hibernate and JPA. I started hibernate before but left it because of other demands.
I am currently using JPA and Hibernate as a persistance provider integrated with Spring. I have a question,
that when we write query statements, can we directly write HQL in JPA. Will that work or we have to write
queries specific to JPA.

Please help,
 
Reddy Prashanth
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can consider JPA query language as a sub set of HQL. HQL supports all JPA QL features and provides additional ( vendor specific) extensions like Criterion, Query By Examples...etc.

If you use JPA queries , your application will be less coupled with hibernate.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks for your quick turn-around.

On note of that, i have another question. What will be best practice, what query language to use, when you are using
JPA but persistance provider as Hibernate? Will HQL be the appropriate choice or JPA own query language?

Best Regards,
 
Reddy Prashanth
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer JPA queries as much as possible. But if your application is using hibernate implementation and if there is no plans in future to move off from hibernate, you can also use Hibernate Queries.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic