Questions tagged [hql]

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 operates with Java Persistence API (JPA) entity objects rather than directly with database tables.

HQL can also be used on platforms such as Adobe ColdFusion

5074 questions
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
  • 6,516
  • 4
  • 29
  • 27
29
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
  • 691
  • 1
  • 6
  • 8
29
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
  • 948
  • 1
  • 7
  • 14
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,761
  • 8
  • 50
  • 80
28
votes
2 answers

Why does Hibernate execute multiple SELECT queries instead of one when using @Fetch(FetchMode.JOIN)

I've got the following query which I expect to run in a single select request: @NamedQuery(name=Game.GET_GAME_BY_ID1, query = "SELECT g FROM Game g " + "JOIN FETCH g.team1 t1 " + "JOIN…
maximus
  • 4,201
  • 15
  • 64
  • 117
27
votes
4 answers

Hibernate and Unexpected end of Subtree exception

I'm a newbie to Hibernate. I have an Item POJO which contains a Set consisting of labels. The labels are contained on another Database table from the Item table, so I do a join to populate the pojo. I'm trying to run a simple example query…
Scott Fines
  • 759
  • 1
  • 5
  • 10
26
votes
3 answers

@NamedQuery over @NamedNativeQuery

Is there any benefit of using @NamedQuery over @NamedNativeQuery in hibernate or vice verse. I cant spot the exact difference or in which context we should use @NamedQuery over @NamedNativeQuery Thanks in advance.
Abhi
  • 6,471
  • 6
  • 40
  • 57
26
votes
4 answers

How to retrieve only certain fields of an entity in JPQL or HQL? What is the equivalent of ResultSet in JPQL or HQL?

In JPQL, I can retrieve entities by : query = entityManager.createQuery("select c from Category c"); List categories = query.getResultList(); But, if I wish to retrieve the id and name fields (only) of the Category entity, I need…
Daud
  • 7,429
  • 18
  • 68
  • 115
25
votes
2 answers

Duplicates using left join fetch

I'm using a HQL query to obtain certain records. If I use LEFT JOIN FETCH a collection which is in my target entity will contain duplicate records. If I only use left join, it won't. I guess when Hibernate lazily loads the records, it avoids…
Daniel
  • 834
  • 1
  • 9
  • 25
25
votes
6 answers

Using Hibernate query : colon gets treated as parameter / escaping colon

return sessionFactory.getCurrentSession(). createQuery("FROM Weather WHERE city_id = :id AND date " + "BETWEEN now()::date AND now()::date + (:days - 1)"). setInteger("id",…
Jaanus
  • 16,161
  • 49
  • 147
  • 202
25
votes
6 answers

Hibernate query for selecting multiple values

In hibernate I can do following Query q = session.createQuery("from Employee as e"); List emps = q.list(); Now if I want to fetch int and String how can I do it? Query q = session.createQuery("SELECT E.firstName,E.ID FROM Employee…
user93796
  • 18,749
  • 31
  • 94
  • 150
24
votes
1 answer

Spring data jpa. Find max if no result return default value

I've implemented in my spring repository interface: @Query("SELECT max(ch.id) FROM MyEntity ch") Long getMaxId(); It works correctly if db is not empty. If I start my environment with test configuration (H2DB is used) - there is no data in the very…
Sergii
  • 7,044
  • 14
  • 58
  • 116
24
votes
2 answers

Hibernate could not locate named parameter even if it exist

Hibernate Keeps detecting org.hibernate.QueryParameterException: could not locate named parameter [name] even though it exist. here's my hql Query query = sess().createQuery("from UserProfile where firstName LIKE '%:name%'").setParameter("name",…
user962206
  • 15,637
  • 61
  • 177
  • 270
24
votes
1 answer

How do I use order by in HQL?

I want to execute my HQL query like this: Query queryPayment=sixSession.createQuery("from Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and payment_date>:pdate) order byvcode."+order +"desc") .setParameter("p_Vcode",…
AFF
  • 1,515
  • 4
  • 21
  • 35
23
votes
6 answers

Hibernate - HQL pagination

This is a problem similar to: HQL - row identifier for pagination I'm trying to implement pagination using HQL. I have a PostgreSQL database. int elementsPerBlock = 10; int page = 2; //offset = 2*10 String sqlQuery = "FROM Messages AS msg " + …
iliaden
  • 3,791
  • 8
  • 38
  • 50