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

How to convert Criteria Example Query to Lucene Full Text Query?

Hi i need help to convert Hibernate criteria query to Lucene Full Text Query, this is possible?, this is my criteria query code @Transactional(readOnly = true) public List example(Cliente cliente){ Session session =…
Israel Perales
  • 2,192
  • 2
  • 25
  • 30
0
votes
1 answer

how to make toUpperCase in hibernate Restrictions

I wrote my code like this criteria.add(Restrictions.eq("lastName", "ChARaN").ignoreCase()); // This by default converting both to lower case. SQL generated: select this_.ID as ID1_0_0_, this_.EMAIL as EMAIL2_0_0_, this_.FIRST_NAME as…
Charan
  • 31
  • 1
  • 5
0
votes
1 answer

How Can I write The Following Query In hibernate Criteria

Select * from Table A left join Table B on A.id=B.id and A.langCode='IN'; where 'IN' is input from user. Table A and Table B has Mapping For Id but there is no Mapping with LangCode between the two as table B dosent have an column called langCode…
0
votes
1 answer

Hibernate Crertira returns duplicates

I have a table purchase, with DDL of : CREATE TABLE purchase ( idpurchase serial NOT NULL, code character varying(50), date timestamp without time zone, totalht double precision, tva double precision, totalttc double precision, …
abdou amer
  • 819
  • 2
  • 16
  • 43
0
votes
2 answers

How to bulid a criteria query to get the data of my domain

I know that have to be really easy, but I'm new in grails and I don't find any clear answer. That I want to do is read and get with a criteria query the data that I have in my domain do a search for each parameter. This is my domain Person: …
S.P.
  • 2,274
  • 4
  • 26
  • 57
0
votes
0 answers

Apply where clause on Sub-Class using HQL

I have one scenario as following Class A { String id; List lstB; } Class B { String id; String name; } Class C extends B { String location; } For above mapping here is my Hibernate mapping
Navnath
  • 1,064
  • 4
  • 18
  • 34
0
votes
2 answers

Hibernate Composite Key Nested Object Criteria Missing From Clause

Currently I am trying to use hibernate (version 4.3.Final) to retrieve an object with a composite primary key containing another hibernate bean association. The criteria I am using is as…
0
votes
1 answer

Hibernate order by column in detached tables

I have 4 tables. For this question I name them tableA, tableB, tableC, tableD. tableB looks something like that: id, name, label, some_other_parameters tableC looks something like that: id, code, some_other_parameters tableD…
Caroline
  • 232
  • 1
  • 2
  • 11
0
votes
1 answer

Hibernate criterion exclusive restriction

I need to implement a filter function using Hibernate Conjunction or Criterion that: Accepts a String containing any of the letters 'A', 'F', 'C', 'I' at most one time in a random order. Returns a Hibernate criterion that evaluates as true if and…
Yiannis Tsimalis
  • 739
  • 2
  • 11
  • 23
0
votes
2 answers

How to left or right join in criteria query in grails

I am using grails 2.1.1. Here I have 2 domain. One is -InvIssue- and other is -SlsDoMst-. There is a foreign key of SlsDoMst in InvIssue domain. Now I need to find all the SlsDoMst row that is not in InvIssue table. So far I am using plain sql for…
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82
0
votes
2 answers

Hibernate criteria query to display children

I am trying to develop a currently very simple web application using Hibernate for the data portion. Basically, I am attempting to get a table with a row for each category. In one cell for each row, I want to display the KPIs for that category. To…
Andrew
  • 8,445
  • 3
  • 28
  • 46
0
votes
2 answers

Left Join with Sub Query in grails?

How do i write below query in Grails either using criteria query or executeQuery? select * from table1 as t1 left Join(select * from table2 where id=2)as t2 On t2.table1=t1.id ;
Ankit Tater
  • 599
  • 3
  • 9
  • 26
0
votes
0 answers

Hibernate restrictions

I have a class named as Films and it has id, filmName, actionStatus and so on. I want to take the filmNames where its actionStatus=4. There are many filmNames with actionStatus=4. I tried to do it this way: Session ses =…
mkmp
  • 142
  • 2
  • 9
0
votes
1 answer

In Hibernate, how do I create a Criteria-restriction object with a function operation trunc on a column name?

select * from tableA where trunc(order_date) > sysdate -7; Something like Criteria criteria = getSession().createCriteria(TableA.class). add(Restrictions.gt("orderDate", afterSubtracting7DaysFromToday));
kshah
  • 11
  • 2
0
votes
0 answers

How to use Restrictions.and for joined table?

I want to get all questions marked by tags "one" and "two" with Criteria API: Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Question.class); if (tags != null && tags.length > 0) { criteria.createAlias("tags",…
sinedsem
  • 5,413
  • 7
  • 29
  • 46