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
34
votes
2 answers

How to simulate NVL in HQL

I tried this: from Table where (:par1 is null or col1 = :par1) but it happens that from Table where :par1 is null always returns all the rows of the table, even if the :par1 is not null. while select * from table where col1 = 'asdf' does not…
Pau
34
votes
2 answers

How do I use the current date in an HQL query with an Oracle database?

I'm trying to write this query using Hibernate 3 and Oracle 10. from Alert alert where alert.expiration > current_date() order by alert.priority, alert.updated, alert.name It's creating SQL like this - Hibernate: select alert0_.ANNOUNCEMENTS_ID…
bpapa
  • 21,107
  • 23
  • 95
  • 147
33
votes
3 answers

HQL Query to check if size of collection is 0 or empty

I try to generate a HQL query that include user with a empty appoinment collections(mapped by OneToMany): SELECT u FROM User u JOIN u.appointments uas WHERE u.status = 1 AND (uas.time.end < :date OR size(uas) = 0) I tries it on several manners (NOT…
Michel
  • 8,310
  • 13
  • 41
  • 56
33
votes
2 answers

How to write a query in hibernate for count(*)

I want to execute the below query in Hibernate? select count(*) from login where emailid='something' and password='something'
user2510115
  • 604
  • 2
  • 8
  • 16
32
votes
2 answers

HQL query with LIKE having issues

I am working on a search query using HQL and everything works find until I get to the LIKE clause. No matter what I do it does not seem to execute the LIKE clause properly. Here is my query. String QUERY = "FROM Person as p WHERE p.createUser = :…
medium
  • 3,708
  • 14
  • 50
  • 63
32
votes
5 answers

HQL query for entity with max value

I have a Hibernate entity that looks like this (accessors ommitted for brevity): @Entity @Table(name="FeatureList_Version") @SecondaryTable(name="FeatureList", pkJoinColumns=@PrimaryKeyJoinColumn(name="FeatureList_Key")) public class FeatureList…
rjsang
  • 1,727
  • 3
  • 16
  • 25
32
votes
5 answers

Optional parameters with named query in Hibernate?

Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate? I'm using a native SQL query, but the question is probably…
Ickster
  • 2,111
  • 4
  • 22
  • 42
32
votes
3 answers

HQL Hibernate INNER JOIN

How can I write this SQL query in Hibernate? I would like to use Hibernate to create queries, not create the database. SELECT * FROM Employee e INNER JOIN Team t ON e.Id_team=t.Id_team I created entity classes in SQLServer2008,…
szefu
  • 381
  • 1
  • 4
  • 10
30
votes
7 answers

Ignore a FetchType.EAGER in a relationship

I have a problem with EAGERs relationships in a big application. Some entities in this application have EAGER associations with other entities. This become "poison" in some functionalities. Now my team needs to optimize this functionalities, but we…
Dherik
  • 13,091
  • 10
  • 86
  • 132
29
votes
2 answers

New object with HQL

Trying to create an object from an HQL query, but just can't figure out what i'm doing wrong. Query: String query = "SELECT product.code, SUM(product.price), COUNT(product.code) from Product AS product GROUP BY product.code" (or should I use new…
Indrek
  • 5,946
  • 4
  • 26
  • 27
29
votes
5 answers

[Ljava.lang.Object; cannot be cast to

I want to get value from the database, in my case I use List to get the value from the database but I got this error Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to…
splatter_fadli
  • 663
  • 3
  • 15
  • 30
29
votes
2 answers

Cannot convert '0000-00-00 00:00:00' to TIMESTAMP

the field definition /** Date. */ @Column(columnDefinition = "datetime") private Date date; setter public void setDate(final Date date) { DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { this.date =…
Oleksandr
  • 3,552
  • 8
  • 43
  • 78
28
votes
4 answers

Hibernate: How to get result from query with multiple classes

If my query contains one class, like: query = session.createQuery("select u from User as u"); queryResult = query.list(); then I iterate it, where queryResult is an object of User class. So how to get result from query which contains more than one…
yaya
  • 291
  • 1
  • 3
  • 7
28
votes
2 answers

Group by month with criteria in Hibernate

I'm trying to get a report using Criteria and ProjectionList, and I'm pretty new using this through hibernate. So I have this model: private Long _userId; private Category _category; private Long _companyId; private Double _amount; private…
RoD
  • 671
  • 1
  • 6
  • 8
28
votes
3 answers

How to view the value of a hive variable?

How do you view the value of a hive variable you have set with the command "SET a = 'B,C,D'"? I don't want to use the variable- just see the value I have set it to. Also is there a good resource for Hive documentation like this? The Apache website…
abu
  • 898
  • 1
  • 7
  • 14