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
67
votes
8 answers

Hive Data Retrieval Queries: Difference between CLUSTER BY, ORDER BY, and SORT BY

On Hive, for Data Retrieval Queries (e.g. SELECT ...), NOT Data Definition (e.g. CREATE TABLES ...), 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…
cashmere
  • 2,811
  • 1
  • 23
  • 32
62
votes
4 answers

Not supported for DML operations with JPA update query

This has been asked once before but the solution did not solve the issue. I am creating a JUnit test: @Test @Transactional @Modifying public void updateMaterialInventory() throws Exception{ // Initialize the database …
Mike3355
  • 11,305
  • 24
  • 96
  • 184
60
votes
3 answers

No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL

I have the HQL where I trying to get artifacts that have no classification (when active is 0) artifacts = Artifact.findAll("FROM Artifact WHERE id NOT IN ( SELECT artifact_id FROM Classification WHERE active = 1) AND document_id =…
krs8785
  • 1,097
  • 2
  • 14
  • 24
56
votes
4 answers

How do I write hql query with cast?

I need to combine 2 tables using hql, both are having common column, but table1 common column is integer and table2 common column is String For example, select a.id as id,a.name as name,b.address as address from Personal as a,Home as b where…
ver
  • 561
  • 1
  • 4
  • 4
55
votes
4 answers

One-To-Many relationship gets duplicate objects without using "distinct". Why?

I have 2 classes in a one-to-many relationship and a HQL query that is a bit strange. Even if I have read some questions already posted, it does not seem clear to me. Class Department{ @OneToMany(fetch=FetchType.EAGER, mappedBy="department") …
bogdan.herti
  • 1,110
  • 2
  • 9
  • 18
49
votes
4 answers

HQL left join of un-related entities

I have 2 entities, A and B. They are related but I do not want to add the relationship mapping to the beans. How can we use left outer join between A and B using HQL or criteria? There are some workarounds available for this, Use Native SQL as told…
ManuPK
  • 11,623
  • 10
  • 57
  • 76
47
votes
1 answer

What's wrong with this HQL? "No data type for node"

session.createQuery("Select attribute from GoodsSection tgs " + "join gs.ascendants ags join ags.attributes attribute " + "where attribute.outerId = :outerId and tgs = :section ") .setString("outerId", pOuterId) .setEntity("section",…
alamar
  • 18,729
  • 4
  • 64
  • 97
45
votes
2 answers

passing list to IN clause in HQL or SQL?

I get List by executing a query. This must be passed to another query of IN clause values. How to pass them in HQL? We can convert List to Array and can pass it, that's not a problem. Finally, I must pass the list in List or Array…
Mr.Chowdary
  • 3,389
  • 9
  • 42
  • 66
44
votes
7 answers

How to test HQL queries?

I'm searching for a fast (really fast) way to test changes to hibernate queries. I have a huge application with thousands of different HQL queries (in XML files) and 100+ mapped classes and i dont want to redeploy the whole application to just test…
Chris
  • 15,429
  • 19
  • 72
  • 74
42
votes
5 answers

how to return Map with HQL

i have a table Permission: id name desc what i am doing right now is to make a query that returns a permission object then put the values in the map programmatically 1- But i was wondering if it's possible to make an HQL (or native sql if not…
fresh_dev
  • 6,694
  • 23
  • 67
  • 95
42
votes
5 answers

How to limit result in @Query used in Spring Data Repository

I am retrieving data by CrudRepository in Spring Data JPA. I want to filter my records those are retrieved from my custom query provided in @Query annotation. I tried .setMaxResults(20); for select rows.. But it gives errors. I want to filter first…
Nipun Vidarshana
  • 451
  • 1
  • 5
  • 12
41
votes
4 answers

Join without association in HQL

Lets say I have two tables(A, B) like: A {id, a, c} B {id, b, c} I have also their entities. I want to write an HQL so that the result set will be like (where A.c = B.c): (a1, b1, c1) (a2, b2, c2) (a3, b3, c3) ... Since on clauses are not…
nimcap
  • 10,062
  • 15
  • 61
  • 69
41
votes
3 answers

org.hibernate.QueryException: JPA-style positional param was not an integral ordinal

I have the following JPQL request; @Query(value = "select req_t " + "from TransactionRelation tr " + "inner join tr.requestTransaction req_t " + "inner join req_t.transactionStateHistory req_t_h " + "inner join…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
41
votes
11 answers

Is there a more efficient way of making pagination in Hibernate than executing select and count queries?

Usually pagination queries look like this. Is there a better way instead of making two almost equal methods, one of which executing "select *..." and the other one "count *..."? public List findCats(String name, int offset, int limit) { …
serg
  • 109,619
  • 77
  • 317
  • 330
40
votes
2 answers

Does between in HQL compare strictly or not?

if I write in HQL A between 5 and 10 is that equivalent to A >= 5 and A <= 10 or A > 5 and A < 10 or some other of the 4 combinations?
flybywire
  • 261,858
  • 191
  • 397
  • 503