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

Will Hibernate findByCriteria cause Java heap memory issue?

I have little knowledge about Hibernate. I am calling findByCriteria(DetachedCriteria criteria) method, but I noticed that it returns a List. My worry is if it will cause Java heap memory issue when the database returns very large result. In my next…
user3123690
  • 1,053
  • 5
  • 17
  • 27
0
votes
1 answer

Criteria, need select only root fields

I have the problem with Hibernate criteria. I need get list of Company by some dynamic conditions and also by condition on Empoyee field (LAZY field). I created Criteria like this: Criteria criteria =…
Akvel
  • 924
  • 1
  • 15
  • 32
0
votes
2 answers

How to use Id autoinkriment at Hibernate?

Probably a silly question but I don't get it. So I've got a class like: @Entity @Table(name="colour" ,catalog="car_store" ) public class Colour implements java.io.Serializable { private Byte id; private String name; private…
user3623571
  • 47
  • 1
  • 7
0
votes
1 answer

Make a hibernate criteria that return all objects with same objects on sublist

My problem is: I have a class that contains a specific list of objects and I need to return all the class objects whose list contains a specific sublist that I passed as param. For example: class A{ List b; } Criteria criteria =…
0
votes
2 answers

How to write the following MYSQL query in criteria query and hibernate query?

How can I write the criteria query and hibernate query for the following MySQL query SELECT * FROM (SELECT * FROM outdatadetail where algorithmno="a0025_d2" and stringno=01 ORDER BY testid desc) sub_query GROUP BY subjectid; Any suggestions.
Vinod
  • 2,263
  • 9
  • 55
  • 104
0
votes
2 answers

Issue with get max id in criteria?

I am unable to get max id from table. How can we get max id. My query is as follows, Criteria tot = sessionFactory.getCurrentSession().createCriteria(student.class); tot.add(Restrictions.eq("surveyId",send_Survey)); tot.add(Restrictions.eq("testId",…
Vinod
  • 2,263
  • 9
  • 55
  • 104
0
votes
1 answer

getting ? in place of ID while using HibernateCriteria subquery

I am getting a weird issue while using the hibernate Criteria for a inner query. Below is the code snippet. Criteria criteria = session.createCriteria(Restaurant.class); criteria.addOrder(Order.asc("nid")); DetachedCriteria innerIDs =…
santu
  • 665
  • 2
  • 7
  • 23
0
votes
1 answer

How to have criteria from multiple entities Hibernate

I have entities like this: @Entity @Table(name = "titul") public class Titul { @OneToMany(mappedBy = "titul") private Set autorstvo; @Column (name = "nazov") private String nazov; } @Entity @Table(name = "autorstvo") public…
Ricsie
  • 319
  • 5
  • 14
0
votes
1 answer

Adding a DetachedCriteria-subcriteria to a projectionList

i want to construct a a pojo with some records from 2 tables using Hibernate criteria api. I'm constructing a ProjectionList with needed records from the 1st table, because i don't have a bidirectional relationship between the 2 tabls , have only…
Eli
  • 59
  • 5
0
votes
1 answer

How can I get the correct select with criteria?

I have some related clases and I want to get a simple select if is made with sql I just want make SELECT * FROM person WHERE id_person_type = 1 But hibernate is bringing me another select I am using version 4.3.5.Final Here are my clases with less…
Rys
  • 4,934
  • 8
  • 21
  • 37
0
votes
3 answers

Restrictions don't work for createAlias

Here is my problem: I want to do something like this query via hibernate criteria select employee.name, employee.surname, department.name, position.name, department_position.end_date from employee, department_position, department, position …
fi11er
  • 679
  • 5
  • 13
0
votes
1 answer

get max of two related colums of the same table with hibernate criteria

Using hibernate criteria, and with the next table: user category subcategory A 1 1 A 1 2 B 1 1 B 2 1 ¿What is the best way to obtain the users with the max category and max subcategory? The criteria…
0
votes
2 answers

Hibernate criteria subquery referring to value from "root" query

I'm working in Grails & Groovy but this is a hibernate question. Here's my Grails domain class: public Card { // implicit Long id String name // ... and over a dozen other fields with various types. } I currently have this Hibernate…
Ian Durkan
  • 1,212
  • 1
  • 12
  • 26
0
votes
1 answer

one-to-many relation and multiple conditions using Criteria

I have 2 tables: a master table with single attributes of some objects (id, name, title, ...) a table with repeating attributes (master_id, attribute_name, attribute_value) Example data for #2: - 10, "authors", "John Bill" - 10, "authors",…
0
votes
1 answer

How to write Criteria query?

I have two entities called EmployeeEntity and EmployeeDeparmentEntity.If I fetch the employee I want fetch all departments which are active.I have used bi-directional mapping for both entities. EmployeeDeparment @Entity public class…
user3214269
  • 219
  • 2
  • 8
  • 23
1 2 3
99
100