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
5
votes
3 answers

Alias for properties that exist only in subclasses (Hibernate Criteria)

Consider the class Operation, and its 3 subclasses: class Operation {} class OpA extends Operation { } class OpB extends Operation { Account account; } class OpC extends Operation { Account account; } Only OpB and OpC have a field called…
Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
5
votes
2 answers

Hibernate: Criteria API vs. QueryDsl

I have some experience with Criteria API but I have never used QueryDsl before. What I want to ask is what are the advantages/disadvantages of using QueryDsl instead of Criteria API? Especially I want to learn which one is more suitable for huge…
hellzone
  • 5,393
  • 25
  • 82
  • 148
5
votes
1 answer

Hibernate Criteria to query more than one class (or restrict by a list of subclasses)

Suppose I have some classes, like this: OpA extends Operation OpA1 extends OpA OpA2 extends OpA OpB extends Operation OpB1 extends OpB OpB2 extends OpB OpB3 extends OpB OpC extends Operation Operation …
Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
5
votes
1 answer

CriteriaBuilder in JPA - where clause

Am new to JPA. Building the select query with the where clause. I need to select from table Contacts all ContactName's that equals the value of the String name. Used the code below to create DB table: CREATE TABLE Contacts ( ContactId BIGINT…
Dipali
  • 65
  • 1
  • 1
  • 6
5
votes
3 answers

How to prevent duplicate results in Hibernate?

When trying to search for multiple values of a relation, duplicate results are returned. How can I avoid these duplicates? We have a method on our service that builds the Criteria: @Override protected Criteria createCriteria(Map
Koohoolinn
  • 1,427
  • 6
  • 20
  • 29
5
votes
1 answer

Hibernate Criteria with Oracle analytic windowing function

Trying to override Oracle10gDialect and adding in over and partition functions. I read on hibernate.org about how to override the dialect. I am using Hibernate 4.1.7.Final and cannot upgrade. I implemented it as specified, however i am getting this…
5
votes
2 answers

Please provide example for an If statement in hibernate criteria

How do you write criteria on if condition using hibernate criteria. My query that needs to be transformed is SELECT date, product, IF(type = 'msrp', amount, 0) price, IF(type != 'msrp', amount, 0) tax FROM productdetail group by date,…
Balaji
  • 859
  • 1
  • 16
  • 27
5
votes
1 answer

How do I resolve "Unable to resolve attribute [organizationType.id] against path" exception?

I'm using Spring 3.1.1.RELEASE, Hibernate 4.1.0.Final, JUnit 4.8, and JPA 2.0 (hibernate-jpa-2.0-api). I'm trying to write a query and search based on fields of member fields. What I mean is I have this entity … @GenericGenerator(name =…
Dave
  • 15,639
  • 133
  • 442
  • 830
5
votes
1 answer

Does Hibernate's Criteria API still not support nested relations

I'd like to use Hibernate's Criteria API for precisely what everybody says is probably its most likely use case, applying complex search criteria. Problem is, the table that I want to query against is not composed entirely of primitive values, but…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
5
votes
2 answers

How are Booleans sorted?

I am sorting with the following code: undoneCategories = session.createCriteria(Category.class); undoneCategories.add(Restrictions.eq("Done", false)); undoneCategories.addOrder(Order.asc("UpwardGenerator")); undoneCategories.setMaxResults(1); where…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
5
votes
3 answers

How to use Hibernate Criteria API without Entity classes?

I want to exploit the db independent HQL and Type safety of Criteria API. But I don't have entity classes. Can I use Criteria API directly?
Sumeet Jindal
  • 882
  • 1
  • 7
  • 16
4
votes
1 answer

Hibernate: Query By Example equivalent of association Criteria Query

I'd like to search my data source for all object instances based on the values of an object related by association. The data model can be simplified to: object of type A holds a list of objects of type B. The goal is to find all instances of A where…
filip-fku
  • 3,265
  • 1
  • 21
  • 19
4
votes
2 answers

Is Hibernate Criteria API stable for future usage?

I mostly use Hibernate criteria API in my previous project. I found Hibernate criteria Expression is already deprecated! Is Hibernate Criteria API stable for future…
THIHA SOE
  • 165
  • 4
  • 9
4
votes
3 answers

Where should I use Hibernate Criteria in MVC architecture?

I am working on a CRM project that uses Spring MVC and Hibernate and I do not know what is the best place to use hibernate criteria. I want to use hibernate criteria because we have search capability on our presentation layer and users can search…
4
votes
2 answers

Criteria API and JPQL API with GROUP BY and GROUP_CONCAT with DISTINCT / ORDER BY / SEPERATOR Support?

Using JPA Criteria API, I want to group by a column and join the values of another column. For example, the below is the sql approach and I am looking for the equivalent criteria query (and jpql query) approach. mysql> select *from…
samshers
  • 1
  • 6
  • 37
  • 84