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

Create criteria that ignores specific character

I would like to create criteria or add restriction to my existing criteria (i think it has to be criteria) that will ignore "-" when searching for data's. E.g I'm searching for number "888" and I would like to get "8-8-8" too. I have bean that…
lukaszrys
  • 1,656
  • 4
  • 19
  • 33
0
votes
0 answers

Hibernate Criteria for Pagination

I am trying to fetch 10 rows or records per page using the Hibernate code as below, List sportsList = session .createCriteria(SportsDAO.class) .setFirstResult((Integer.valueOf(pageNo) - 1)* 10) …
Harish
  • 181
  • 1
  • 3
  • 11
0
votes
2 answers

How to Return Object using HQL query resultset in Openbravo

Hi I am openbravo beginner. I would like to know about the returning object from HQL query resultset. Normally I could return list or string. When I am trying to return Object its showing error like cannot cast object to string. Here my object is :…
0
votes
1 answer

JPA Criteria Builder build a predicate on a setAttribute

I am new to using Criteria Builder for building dynamic queries. I am trying to create a specification for my repository to find the DVD titles that contain a description like the search term. I have a many to many join between dvds and dvd…
Sarah92
  • 671
  • 4
  • 12
  • 29
0
votes
1 answer

Select Distinct column and Another Column - Oracle Hibernate

I need to select distinct id and also need another column MyClass class1 = new MyClass(); Criteria criteria = new Criteria(MyClass.class); ProjectionList projList = Projections.projectionList(); …
Prashanth
  • 31
  • 7
0
votes
2 answers

Hibernate: dynamic join multiple tables

I'm new to Hibernate and I'm trying to dynamically join more table. I have built an example with three tables: Employee, Address, Country. I want to retrieve all employees of a certain country. Here my config file:
Neo
  • 1,337
  • 4
  • 21
  • 50
0
votes
1 answer

Using hibernate criteria query for joining a not directly referenced entity

I would like to run a criteria query on an entity using a join with another entity. But from Java/Hibernate point of view there is no reference to this second entity, there is only one from this second to the first entity. To make it understandable,…
Marcel
  • 4,054
  • 5
  • 36
  • 50
0
votes
2 answers

Hibernate criteria how to get rows with max column value

I have a table like below: user_id number 1 10 2 17 1 12 2 18 I mean one user can have more than one row. I have to reach following result: user_id number 1 …
Gary Leather
  • 281
  • 2
  • 6
  • 18
0
votes
2 answers

Hibernate criteria left our join

I have the following entities: Machines { id, name } Favorites { userId, objectId, objectType } Now I want to return list of machines ordered by favorites, name. Favorites does not have any relation with Machines entities, its a…
Chaitanya
  • 2,396
  • 4
  • 29
  • 45
0
votes
0 answers

CriterialBuilder, specification, and Predicate. Spring Data solution for Oracle sql exists clause

I have a sql which is similar to the following. (As I cannot use production database table names and the query is quite messy) select book_name, auther_name, price from library_books where book_name=?1, auther_name = ?2, price < ?3 and exists…
TV Nath
  • 499
  • 5
  • 12
  • 35
0
votes
1 answer

Hibernate Criteria and metamodel

I could not find anywhere if it possible to create metamodel over entites to be used in Hibernate's Criteria API. So I don't have to write strings for fields, but rather rely on the generated metamodel similarly as it can be done with JPA Criteria…
redhead
  • 1,264
  • 1
  • 17
  • 32
0
votes
0 answers

Hibernate criteria specific query

I have such entity: public class LogEntity implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private Date changeTime; private Set changes; //getters and setters } And…
Ilya
  • 1
  • 2
0
votes
1 answer

Criteria Query on Sakila Database

I am new to Hibernate and Criteria Query. I want to perform operations on sakila database. I want a Criteria query for the following SQL query: select c.city, cr.country from city c left join country cr on c.country_id = cr.country_id;
Parag122
  • 11
  • 2
0
votes
1 answer

Hibernate Search using criteria API

I have two entity classes Book and chapter.There is one to many mapping between Book and chapter. I want to search the book and associated chapter by providing book name. I also want to search the chapter and associated book by providing chapter…
bablu
  • 601
  • 1
  • 9
  • 21
0
votes
1 answer

Hibernate Restrictions - how can I query with multiple values?

I am new to Hibernate Restrictions and need some help: I am having a scenario that I need to find all the records where "identifier" is "HB001" or "HB002", "HB003" &"HB004". That is to say, it should return 4 rows, each row has "identifier" as…
Wolfberry
  • 1
  • 1
  • 1