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

Wrong pagination result when removing duplicate records

I am using the criteria below with pagination parameters. There were some duplicate records generated due to join so I used setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY). It removed the duplicate record but it seems that it removes the…
Vivek Sadh
  • 4,230
  • 3
  • 32
  • 49
0
votes
1 answer

JPA 2.0, Write query with multiple conditionals

I have an entity with some fields @Entity public MyEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long id; public UUID uuid; public String value; ..... } Now i would like to create a query which…
hnnn
  • 504
  • 2
  • 7
  • 24
0
votes
2 answers

Java Hibernate Criteria Many-To-One

I am trying to use hibernate with a Many-to-one relationship, as shown below: I have a service table and for each service, we have a programId. public class Service { ... @ManyToOne @JoinColumn(name="PROGRAM_LV_ID", referencedColumnName =…
RadoTonev
  • 45
  • 1
  • 7
0
votes
1 answer

How can I select with hibernate.query from an intermediate table

I have three tables Job, JobSeeker and Job_applications which is the intermediate table. The relation between Job and JobSeeker is n to n. How can I write a hibernate query or criteria to select a List(Job) with Job.id and Job.applicantsCount which…
FAndrew
  • 248
  • 4
  • 22
0
votes
0 answers

Hibernate Criteria Projection Property

I am using Hibernate Criteria Projections Property. I want to test 'IS NULL' condition before adding into Projection List. Consider sample example .add(Projections.property("normalRange"),"normalRange") i want to test this property value IS NULL…
Aravinthan K
  • 1,763
  • 2
  • 19
  • 22
0
votes
1 answer

How to use hibernate criteria for selecting only parent table columns and not child table

Let say we have two tables: dept and emp Now i need to get this query using hibernate criteria: select d. from dept d, emp e where d.id=e.dept_id and d.name='HR' and e.age>25; I tried following: Session session = (Session)…
Ankush
  • 1
  • 5
0
votes
0 answers

Grails find existing record by criteria

I have (among others) two domain classes: class Course { String name ... } class Round { Course course String startweek // e.g. '201504' String endweek // e.g. '201534' String applcode // e.g. 'DA542133' ... } Application codes…
Serafim
  • 484
  • 3
  • 10
0
votes
1 answer

HibernateTemplate findByNamedQueryAndNamedParam very slow

I am working on a new project on some existing code . It uses HibernateTemplate.findByNamedQueryAndNamedParam to invoke a stored procedure in the database . When I execute the stored procedure on the database , it executes in 2 or 3 seconds . But I…
Zak
  • 111
  • 3
  • 11
0
votes
2 answers

SQL | Criteria Query for max value in a subquery

I need to find out the row corresponding to the row in table2 which gives a single row output for the below query. I will be writing a JPA criteria query for this query. I am able to get the max(date) from the subquery but not the exact row…
0
votes
1 answer

How do I write a criteria to exclude some entities

I want to write a hibernate criteria that excludes certain entities. Here's what I have so far: Criterion exclusion1 = Restrictions.not(Restrictions.conjunction() .add(Restrictions.eq("color", "blue"); .add(Restrictions.eq("type", "aaa")) …
0
votes
2 answers

Criteria throws org.hibernate.QueryException: could not resolve property but HQL works

I am trying to retrieve CompanyOnCampus entity using criteria. It has a component class Company. The mapping is like this:
MandarK
  • 143
  • 1
  • 8
0
votes
1 answer

Hibernate ManyToMany and Restrictions.in

I have Article and Tag entities: @Entity @Table(name = "articles") public class Article implements Serializable{ //other things @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) private List tags; } @Entity @Table(name…
0
votes
1 answer

Hibernate Exception - could not locate named parameter

i am trying to extract a list of objects from database from entity (table) StudySeries: @Entity @Table(name="StudySeries", uniqueConstraints = { @UniqueConstraint(columnNames = "SeriesInstanceUID")}) public class StudySeries implements Serializable…
thanili
  • 777
  • 4
  • 26
  • 57
0
votes
1 answer

JPA Cannot join to attribute of basic type

log.debug("get category list start "+id); List usersViewList = new ArrayList(); long a=System.currentTimeMillis(); CriteriaBuilder builder = em.getCriteriaBuilder(); Metamodel …
gangatharan
  • 781
  • 1
  • 12
  • 28
0
votes
1 answer

How to fix an hibernate criteria datepart error?

I have a domain with a calculated field. durationInMinutes formula: 'datepart(minute, Duration) + datepart(hour, Duration) * 60' and use it in a createCriteria property('durationInMinutes') but this generates an error in the…
fpk
  • 65
  • 7