Questions tagged [hql]

Use this tag for questions concerning "Hibernate Query Language" (HQL), a query language used by Hibernate and NHibernate. Use the tag [hiveql] for questions about Hive Query Language.

HQL, acronym for "Hibernate Query Language", is a powerful, object oriented query language used by the Hibernate and the NHibernate object relational mappers.

It is used in Java environments and is heavily inspired by SQL. Its syntax resemble SQL queries, but operate against Java Persistence API (JPA) entity objects rather than directly with database tables.

HQL can also be used on platforms such as Adobe ColdFusion

4854 questions
308
votes
22 answers

JPA and Hibernate - Criteria vs. JPQL or HQL

What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when…
cretzel
  • 18,856
  • 18
  • 55
  • 69
253
votes
14 answers

How do you do a limit query in JPQL or HQL?

In Hibernate 3, is there a way to do the equivalent of the following MySQL limit in HQL? select * from a_table order by a_table_column desc limit 0, 20; I don't want to use setMaxResults if possible. This definitely was possible in the older…
stevedbrown
  • 8,624
  • 8
  • 39
  • 57
221
votes
5 answers

What is the difference between JOIN and JOIN FETCH when using JPA and Hibernate

Please help me understand where to use a regular JOIN and where a JOIN FETCH. For example, if we have these two queries FROM Employee emp JOIN emp.department dep and FROM Employee emp JOIN FETCH emp.department dep Is there any difference between…
abbas
  • 4,704
  • 2
  • 31
  • 30
108
votes
4 answers

JpaRepository Not supported for DML operations [delete query]

I have written a query to delete some objects in my interface extending JPaRepository, but when I execute the query it throws an exception! Can anyone explain it for me? Query: public interface LimitRepository extends JpaRepository
Student
  • 1,083
  • 2
  • 6
  • 6
102
votes
11 answers

How do you create a Distinct query in HQL

Is there a way to create a Distinct query in HQL. Either by using the "distinct" keyword or some other method. I am not sure if distinct is a valid keywork for HQL, but I am looking for the HQL equivalent of the SQL keyword "distinct".
Mike Pone
  • 17,050
  • 12
  • 49
  • 63
90
votes
3 answers

Difference between INNER JOIN and LEFT SEMI JOIN

What is the difference between an INNER JOIN and LEFT SEMI JOIN? In the scenario below, why am I getting two different results? The INNER JOIN result set is a lot larger. Can someone explain? I am trying to get the names within table_1 that only…
user3023355
  • 927
  • 1
  • 7
  • 5
81
votes
3 answers

Proper way of writing a HQL in ( ... ) query

Assuming that I want to write the following HQL query: FROM Cat c WHERE c.id IN (1,2,3) what is the proper way of writing this as a parametrized query, e.g. FROM Cat c WHERE c.id IN (?)
Robert Munteanu
  • 63,405
  • 31
  • 191
  • 270
78
votes
5 answers

IN-clause in HQL or Java Persistence Query Language

I have the following parametrised JPA, or Hibernate, query: SELECT entity FROM Entity entity WHERE name IN (?) I want to pass the parameter as an ArrayList, is this possible? Hibernate current tells me, that java.lang.ClassCastException:…
Daniel
  • 25,883
  • 17
  • 87
  • 130
74
votes
5 answers

ORDER BY using Criteria API

When I write a HQL query Query q = session.createQuery("SELECT cat from Cat as cat ORDER BY cat.mother.kind.value"); return q.list(); Everything is fine. However, when I write a Criteria Criteria c =…
niklassaers
  • 7,810
  • 18
  • 90
  • 141
73
votes
5 answers

Hibernate criteria: Joining table without a mapped association

I'd like to use Hibernate's criteria api to formulate a particular query that joins two entities. Let's say I have two entities, Pet and Owner with a owner having many pets, but crucially that association is not mapped in the Java annotations or…
Snukker
  • 1,903
  • 3
  • 17
  • 18
73
votes
5 answers

Hibernate Criteria vs HQL: which is faster?

I have been reading some anwers, but i'm still confused. ¿Why? because the differences that you have mentioned do not relate with the performance. they are related with easy use.(Objetc(criteria) and SQL(hql)). But I would like to know if "criteria"…
kcobuntu
  • 761
  • 1
  • 6
  • 4
69
votes
2 answers

org.hibernate.QueryException: illegal attempt to dereference collection

I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference…
xrcwrn
  • 4,867
  • 17
  • 58
  • 117
67
votes
3 answers

Hibernate HQL Query : How to set a Collection as a named parameter of a Query?

Given the following HQL Query: FROM Foo WHERE Id = :id AND Bar IN (:barList) I set :id using the Query object's setInteger() method. I would like to set :barList using a List of objects, but looking at the Hibernate documentation and…
karlgrz
  • 13,425
  • 10
  • 43
  • 57
62
votes
7 answers

Hive cluster by vs order by vs sort by

As far as I understand; sort by only sorts with in the reducer order by orders things globally but shoves everything into one reducers cluster by intelligently distributes stuff into reducers by the key hash and make a sort by So my question is…
cashmere
  • 2,571
  • 1
  • 21
  • 32
60
votes
2 answers

Difference between LEFT JOIN and LEFT JOIN FETCH in Hibernate?

I am trying to understand the difference between LEFT JOIN and LEFT JOIN FETCH in Hibernate. Can anyone explain this? Thanks
Barry
  • 1,425
  • 2
  • 21
  • 34
1
2 3
99 100