Questions tagged [hibernate-criteria]

The Criteria interface of Hibernate ORM , represents a query against a particular persistent class. The interface provides access to the powerful mechanism of hibernate criteria API, that allows the programmatic creation of queries against the DB.

Hibernate provides an alternate way of HQL to manipulate objects and it is called Hibernate Criteria Query. The Hibernate Session interface provides createCriteria() method which can be used to create a Criteria object. This criteria object returns instances of the persistence object's class when the application executes a criteria query.

The primary advantage of Criteria Query over HQL and native SQL is that it allows OOP control over the queries and hence it is more dynamic compared to HQL. In order to make HQL dynamic String concatenation needs to be done, which is not considered as a good programming concept.

To learn more about Criteria Query and it's usage the official website of Hibernate is a very good resource.

1659 questions
6
votes
3 answers

Narrowing the result of query by subquery

I'm trying to narrow the result set of Hibernate Criteria query by result of another query. I know how to resolve this problem with JPQL: FROM DocPackage p WHERE EXISTS (SELECT g FROM ObjectGroup g JOIN g.items i, Person per WHERE…
vect
  • 645
  • 8
  • 16
6
votes
1 answer

Case insensitive Restriction.IN

I've googled a bit but found no decent solutions... What i would like to achieve, source comes firts :) List result = session.createCriteria(MyStuff.class) .add(Restrictions.in("name", templates)).list(); templates is a Collection,…
wilu
  • 549
  • 1
  • 12
  • 26
5
votes
5 answers

How to create Criteria on field that can be null?

I have to create create Criteria or Criterion on specific field myProperity (on class MyClass). I have to choose all objects that have prop = null or satisfy specific Criteria. So I should make something like: Criteria criteria =…
M314
  • 925
  • 3
  • 13
  • 37
5
votes
2 answers

How to implement with hibernate criteria Object the select query with inner join

I'm new with Hibernate and Criteria Query. So I have implemented the query in HQL: select A.mobilephone B.userNick C.creditCard from mobile_table A inner join user_table B on A.codmobile=B.codmobile inner join Credit C on…
Bomberlatinos9
  • 790
  • 3
  • 11
  • 24
5
votes
3 answers

Hibernate 6 Error InvalidDataAccessApiUsageException: Illegal pop() with non-matching JdbcValuesSourceProcessingState

Getting Below error , while calling JPA method, frequently in Hibernate 6 org.springframework.dao.InvalidDataAccessApiUsageException: Illegal pop() with non-matching JdbcValuesSourceProcessingState at…
5
votes
2 answers

Pagination with Hibernate criteria and FetchMode.JOIN

I've got two tables, 'Players' and 'Items'. Players have a list of items. I want to retrieve the players, and all of their items, using pagination. I want to paginate based on the players and without regard to how many items there are. So I do…
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
5
votes
0 answers

Hibernate Criteria API is deprecated, but JPA Criteria API is complicated and almost unusable (e.g. for Joins)

My understanding is that the Hibernate Criteria API is deprecated: As of Hibernate 5.2, the JPA Criteria API should be used instead But in Hibernate Criteria API, building complex queries with JOINs was easy. I could do it as follows: Criteria…
gene b.
  • 10,512
  • 21
  • 115
  • 227
5
votes
1 answer

Use Hibernate Criteria API to return first row of each group

I am new to Hibernate and I am trying to write a criteria query to return the latest status of employee on a given date id | Status | status_date 1 | Active | 1/10/2017 2 | Active | 1/10/2017 ... 1 | Inactive| 5/10/2017 ... 1…
Setsuna F. Seiei
  • 192
  • 1
  • 2
  • 13
5
votes
1 answer

In Hibernate 5, what's the CriteriaQuery equivalent of Criteria's restriction and projection?

Before Hibernate 5 deprecated the Criteria class, you could add restrictions to a Criteria to act as a constraint, and projections to act as select statements, like so Criteria criteria = session.createCriteria(T.class) …
adickinson
  • 553
  • 1
  • 3
  • 14
5
votes
2 answers

Hibernate criteria query fetch with embedded id

I have this Entity class: @Entity public class Registered implements Serializable { @Id public RegisteredId id; } With this EmbeddedId: @Embeddable public class RegisteredId implements Serializable { @ManyToOne public User user; …
Atropo
  • 12,231
  • 6
  • 49
  • 62
5
votes
1 answer

Hibernate criteria with projection not performing query for @OneToMany mapping

I have a domain object, Expense, that has a field called initialFields. It's annotated as so: @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true) @JoinTable(blah blah) private final List
Josh
  • 2,842
  • 8
  • 45
  • 51
5
votes
1 answer

How use Hibernate Criteria with searching in Postgresql JSON and use with Lateral

On the client side we have endpoint for searching with filter. On backend I have method for searching in Postgresql DB. One of the option - search into jsonb field. Before this day I searched over values and keys. And my code was: if…
Optio
  • 7,244
  • 2
  • 22
  • 30
5
votes
1 answer

Is this query possible using Criteria or DetachedCriteria Hibernate

The question is simple can this query be done in Hibernate using Criteria or DetachedCriteria? i guess not but i wanted to do this question maybe exist a workaround. SELECT COLUMNS FROM table WHERE id not in ( SELECT * FROM ( SELECT…
chiperortiz
  • 4,751
  • 9
  • 45
  • 79
5
votes
2 answers

Can't create grails Criteria query containing a belongsTo relation

I've been trying to create a criteria builder containing a belongsTo relation and have yet to succeed. Consider the following model: class Msg { ... static belongsTo = [user: User] ... } class User { ... Organisation…
Mr.B
  • 917
  • 1
  • 11
  • 20
5
votes
1 answer

Can we check hibernate criteria alias already exists?

A few minute ago get an error "duplicate alias" and I started the think about "Can we check alias was already created? alias was already exists." Do you know about this? Can we check this? for example : Criteria criteria =…
luffy
  • 315
  • 1
  • 4
  • 22