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 - Restriction between()

Criteria cr=session.createCriteria(Student.class).add(Restrictions.between("strStudentMark1", "90", "100")); In the above code snippet, I have given the mark between 90 and 100. In the Student table, there are fields between marks 90 and 100. but…
Kaushi
  • 198
  • 3
  • 8
  • 20
0
votes
1 answer

How to return hibernate collection entities without returning root entity

I would like to get elements of a collection (Set) for a set of objects (WorkbookConfig) from Hibernate without getting the primary objects(WorkbookConfig). The underlying tables look like this: workbook_config ->…
Organus
  • 169
  • 2
  • 10
0
votes
1 answer

Hibernate criteria returning list which contain same objects, How to resolve it?

I have written restriction as follows, DateFormat df = new SimpleDateFormat("yyyy-mm-dd"); Date frmDate= df.parse("2014-01-01"); Date toDate=df.parse("2014-09-16"); Criteria criteria = session.createCriteria(HistoryLatitudeBean.class); …
Raghu
  • 1,324
  • 7
  • 24
  • 47
0
votes
1 answer

Hibernate Criteria joining unrelated children?

I have three entities with one parents has two children, but I only listed two entities here. @Entity @Table(name = "person") public class Person{ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy =…
user3123690
  • 1,053
  • 5
  • 17
  • 27
0
votes
1 answer

Compare count result

In my database, I have publications and each publication can have zero or more pages, which are stored in another table. When selecting them, I either want to get all publications or only the ones with at least one page. The following criteria query…
user1406177
  • 1,328
  • 2
  • 22
  • 36
0
votes
2 answers

Solving issues with unidirectional OneToMany relationship

I am working with legacy code. I have entity A and entity B class, but because entity B is being referenced many places, I try not to make changes on entity B. Followings are classes for these two entities. Entity B has a foreign key column which…
user3123690
  • 1,053
  • 5
  • 17
  • 27
0
votes
1 answer

Hibernate Search Results Ordering

I am using Hibernate Search to apply full text Search on a field in my database table. I am using it like this: FullTextSession fts=Search.createFullTextSession(session); QueryBuilder qb2 = fts.getSearchFactory().buildQueryBuilder() …
Umair
  • 81
  • 1
  • 1
  • 8
0
votes
1 answer

How to use Hibernate Criteria order by with associate tables?

I have 3 tables. Table A - pk_id, FK_B_Id(foreign key of Table B),... Table B - pk_id, name.... Table C - pk_id, FK_A_Id(foreign key of Table A), name... I’m getting search result based on Table A. In the table A records either associate with table…
Roshan
  • 177
  • 2
  • 9
0
votes
4 answers

Hibernate Criteria: How to create a query for many search fields?

I need to fetch details from DB if any of the fields are entered, the fields are as below Date Code Action Status UserName Application. Kindly help me as any of the fields can be entered and not necessarily all values need to entered. Thanks &…
user3751955
  • 45
  • 1
  • 5
0
votes
1 answer

Hibernate Criteria Api does not provide accurate result list

I am having two tables in database USER_DETAILS and Address. The Entity classes for both the tables are below @Entity @Table(name="USER_DETAILS") public class UserDetails {` @Id @GeneratedValue(strategy=GenerationType.AUTO) private int…
Irshad
  • 1,016
  • 11
  • 30
0
votes
1 answer

Get results from AuditCriterion in new class

I Know that when you do this code: AuditReader reader = AuditReaderFactory.get(entityManager); reader.createQuery().forRevisionsOfEntity(Person.class,false,true).getResultList(); it returns a tree element array. I want this 3 elements…
0
votes
1 answer

How to compare base64 data in database with binary data?

Due to some project requirement I have to convert my DB VARCHAR data into base64(VARBINARY). Now the problem is that while I am trying to query DB from my java application using: criteria.createCriteria("parties").add(Restrictions.ilike("name", "%"+…
Minion
  • 125
  • 1
  • 2
  • 12
0
votes
1 answer

Create a criteria in Grails

I got two domains on my project, first is Applicant and other is Screening. On Applicant I got: String name String age On Screening I got: String status belongsTo: [applicant: Applicant] Now I would like to get all applicants with age <30 and…
Tran Tam
  • 699
  • 3
  • 14
  • 27
0
votes
1 answer

Convert SQL statement to Hibernate Criteria or Projections

I'd like to convert this SQL Statement into either Criteria or Projections. I'm sorry I don't know which one to use since I'm new to Hibernate. I've done some research, and it looks like both are needed to achieve what I wanted. Before I always use…
lxcky
  • 1,668
  • 2
  • 13
  • 26
0
votes
1 answer

Hibernate criteria and/or with many-to-many

This is the query i'm running: List coupons = getDb().createCriteria(Coupon.class) .add(Restrictions.le("validFrom", startTime.getTime())) .add(Restrictions.ge("validUntil", startTime.getTime())) .add(Restrictions.eq("user",…