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
0
votes
1 answer

Hibernate JPA many-to-one self-join association cascade, how to select the top hierarchy and map children?

Based on this example. I try to map an Employee to his manager using Hibernate and JPA annotation. @Entity @Table(name="EMPLOYEE") public class Employee { @Id @Column(name="EMPLOYEE_ID") @GeneratedValue private Long employeeId; …
Alex L
  • 185
  • 1
  • 11
0
votes
1 answer

Hibernate Criteria taking off associations

I have a class Usuario. User have association with UsuarioPerfil: public class Usuario{ /*Attributes*/ @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "id_usuario_perfil", referencedColumnName = "id", foreignKey = @ForeignKey(name =…
Luciano
  • 3
  • 5
0
votes
1 answer

How to join two or more not association entity like as sql joined with on condition

I have entity class, those classes not association but have common property (ex. Serial no). I don't want to write association for tables. I want joined tables like SQL join condition. How do I write criteria query for this issue?
0
votes
0 answers

How to create this criteria/detached criteria based query in Grails

I am trying to complete a criteria query in Grails that sometimes has to refer to an unassociated table, therefore using a detached query. Depending on a passed in parameter, I need to perform a different subquery. I have a Customer domain, which…
David Brown
  • 3,021
  • 3
  • 26
  • 46
0
votes
0 answers

How to write criteria eqivalent of sql having count

I'd like to ask how to create hibernate criteria to get these employees who has more than one project. I have following entities class Project{ public String title; public Employee owner; } class Employee{ public String name; …
akn
  • 3,712
  • 26
  • 43
0
votes
1 answer

Return single column from multi-group Hibernate projection

What I want to achieve: Select a susbset of entities that have a property value that exists in a List of values. This list is returned by another Query. In plain SQL, this can be easily achieved with subqueries. This is the Criteria query that…
feob
  • 1,930
  • 5
  • 19
  • 31
0
votes
1 answer

Translating SQL Functions in Criteria

I'm trying to reproduce this sql query into a hibernate criteria query how can I achieve tha. SELECT * FROM PERSON WHERE BIRTH_DATE IS NOT NULL AND (YEAR(GETDATE()) - YEAR(BIRTH_DATE)) in(6,18,26) ORDER BY MONTH(BIRTH_DATE) ASC, …
Akyo
  • 139
  • 1
  • 12
0
votes
1 answer

How to get objects with max value in Hibernate hql?

I'm working on a query using Hibernate and following is the query List articleP = session.createQuery("select ap, max(ap.lastPrice.price) from ArticleP ap " + "where ap.stock > 0 and ap.article.category.idCategory =…
0
votes
1 answer

Get a specific value in Criteria hibernate String

I need extract some values on criteria String. The concept is to get the real SQL sentence and his parameters (no log) For the moment, I used this for get the Select: CriteriaImpl c = (CriteriaImpl) criteria; SessionImpl s =…
Borz93
  • 3
  • 1
0
votes
0 answers

Execute multiple hibernate dependencies criteria

Firstly, I am very new in hibernate so I don't have any idea how to working with multiple criteria. Basically I have two criteria. First criteria with sub query and I am defining this criteria as below : DetachedCriteria subCriteria =…
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
0
votes
1 answer

Hibernate criteria restriction on join column

My Hibernate bean ContentElementTypeProperty references another Hibernate Bean TestUnitType (Many to One). TestUnitType is a field of ContentElementTypeProperty. In the database, testunittypeid is a column in the…
Jake
  • 4,322
  • 6
  • 39
  • 83
0
votes
2 answers

Hibernate - findByProperty - how to use it with different types

I'm trying to write a search, using Hibernate that would run search on different types of variables. I have a model Movie, that has properties: title, director, genre, year. Title, director, genre are strings, year is an int. In the jsp file I have…
czmadzia
  • 1
  • 1
0
votes
1 answer

how to write POJO in hibernate having joins for more than 2 tables

I am new to hibernate, trying to get information from more than 2 tables using hql, if we pull that information we need to put in a POJO how to do mapping for each column to the information that we get as a result from the query? Tried using…
piyush
  • 115
  • 2
  • 12
0
votes
1 answer

Criteria - where clause on joined table

I have two tables in a MySQL database: COURSE and COURSE_SESSION. COURSE has two fields : code(primary key) and title. CourseSession has a field called course_code which is a foreign key linked to an element of Course. I want to do somthing like…
Nono
  • 33
  • 7
0
votes
1 answer

Group by month in Hibernate Criteria queries

I am new to Hibernate Criteria Queries , I am struggling to get the count based on month. session.createCriteria(Task.class) .add(Restrictions.eq("completed", true)) …
Cork Kochi
  • 1,783
  • 6
  • 29
  • 45