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

Order by on joined collection

I am trying to print the list of posts for an author (id=1) ordered by the published timestamp in descending order. I tried using two approaches shown below: //Query 1 Criteria topCriteria = session.createCriteria(Author.class) …
Anvesh
  • 395
  • 1
  • 2
  • 10
0
votes
2 answers

Grails query: Get list of associated objects

I have a many-to-many relationship: class Project { Set pis : static hasMany = [ pis:PrincipalInvestigator ] } class PrincipalInvestigator { String name : } I want a query that returns a unique and…
sebnukem
  • 8,143
  • 6
  • 38
  • 48
0
votes
1 answer

Using Embedded object property in Grails during Search or FindAllBy

I have a grails Domain called Connection. This domain contains a User instant in it called myFriend. I want to write a Query that returns all the connections where myFriend.firstName is Dave for example. Since this object is embedded within…
AlexCon
  • 1,127
  • 1
  • 13
  • 31
0
votes
2 answers

Hibernate occurs too many queries

I use hibernate(with ehcache)/spring/mysql/jsf.I'am getting data from two tables in mysql.And these tables are as follows: User id int (primary key) name etc. Lesson id int (primary key) lesson varchar teacher_id int (foreign key from user(id)…
erginduran
  • 1,678
  • 5
  • 28
  • 51
0
votes
1 answer

Hibernate in query in 2 different columns?

I am trying to find rows that has one of the values I am looking for in one of the 2 columns. So far I've used a criteria like this but it doesn't find anything. Criterion a = Restrictions.in("oid", workOrderOids); Criterion b =…
0
votes
2 answers

Hibernate sort table based on max year and max month and group by id using criteria

I'm having difficulty representing this query which I write for select max month and max year rows from given 'uid'. I have 6 data in which 3 data has uid '4' and other 3 data has uid '5'. I want to get the max month and max year data from both uid…
Jimmy
  • 1,719
  • 3
  • 21
  • 33
0
votes
2 answers

how to group by columns without projection in hibernate criteria?

i am trying to fetch only max(assetHistoryId) but my below code returing 3 columns max(assetHistoryId), eventId, and assetIdentifier in result. how to group the columns with out projection using criteria. you can find my code below. final Criteria…
0
votes
1 answer

How to make a specific query on mapped objects with hibernate

menu menu_autorization authorization ---------- ----------------------- ----------------------- |id|title| |id|menu|authorization| |id|authorization|info| ---------- …
MDP
  • 4,177
  • 21
  • 63
  • 119
0
votes
1 answer

Criteria to get all Person's, who doesnt own a Ford car

I have a domain class Person, as below class Person { static hasMany=[cars:Car] } Now, i want fetch all Person, who doesn't own a 'Ford' car. The problem with below criteria is that, it fetches 'Person' with two cars, out of which one is…
Ashish Joseph
  • 1,103
  • 3
  • 12
  • 35
0
votes
1 answer

How do I use JPA 2.1's CriteriaBuilder.function with MySQL's "GROUP_CONCAT"?

I’m using JPA 2.1, Hibernate 4.3.6.Final, and MySQL 5.5. I read JPA 2.1 supports invoking native DB functions, but I’m having trouble figuring out how to invoke MySQL's “GROUP_CONCAT.” I have the following code … final CriteriaBuilder builder =…
Dave A
  • 2,780
  • 9
  • 41
  • 60
0
votes
1 answer

Strange phenomena in hibernate not in with criteria

I have two tables with many-to-many relationships which called Position and Content. Mapping is collect, because insert and and other queries all can work properly. and I use Criteria c =…
0
votes
2 answers

hibernate hbm: automatic (unwanted) update found

In my project I use hibernate hbm and spring,i run an sql query to update a single column, Query sql = getSession().createSQLQuery("update HISTORIQUE_DETAIL_APPELS set token_otp = '"+historiqueDetailAppelsVO.getCodeOtp()+"' where id = …
CHHIBI AMOR
  • 1,186
  • 2
  • 13
  • 27
0
votes
0 answers

SqlProjection - cannot use entity name and cannot use {alias} to compare

I have a two part question. I am using Criteria and Projections to retrieve data. I am mapping the resultant data set to a DTO. I had to use SqlProjection to get some data, but it seems the sql projection does not accept the Entity name, but its…
evyavan
  • 35
  • 8
0
votes
3 answers

spring mvc hiberate, use CriteriaQuery to run select * from table where

what i need is to run a sql query something like : select * from table where alpahbetcolumn="A" and numbercolumn="10" and shelfcolumn="upper"; i want to know how to do this query in hibernate using EntityManager currently this is my own try out,…
sefirosu
  • 2,558
  • 7
  • 44
  • 69
0
votes
1 answer

Hibernate query for left outer join with null id condition

Is any hibernate query similar to the following query? MySql Query >> select * from mother mot left join children ch on ch.mid = mot.id where ch.id is null mot.id - primary key of mother ch.mid - foreign key ch.id - primary key of children
Fire Ratz
  • 3
  • 1