Questions tagged [criteria]

Mechanism typical to ORM frameworks that allows the creation of queries against a database in a dynamic and object-oriented fashion. When writing a query using Criteria one uses an API instead of writing a query using a defined language (SQL).

Mechanism typical to ORM frameworks that allows the creation of queries against a database in a dynamic and object-oriented fashion. When writing a query using Criteria one uses an API instead of writing a query using a defined language (SQL).

All the most known ORM frameworks provide Criteria APIs, like Hibernate Criteria and after the release of JPA it was standardized as JPA Criteria.

2829 questions
24
votes
2 answers

setResultTransformer in Criteria

What is the use of setResultTransformer method in criteria API? Can someone explain this with a simple example? I read the javadocs but i am not able to understand them clearly. Regards,
user182944
  • 7,897
  • 33
  • 108
  • 174
23
votes
3 answers

(Lazy) LEFT OUTER JOIN using the Hibernate Criteria API

I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method: Criteria criteria = this.crudService .initializeCriteria(Applicant.class) …
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103
22
votes
6 answers

Hibernate Query By Example and Projections

To make it short: hibernate doesn't support projections and query by example? I found this post: The code is this: User usr = new User(); usr.setCity = 'TEST'; getCurrentSession().createCriteria(User.class) .setProjection( Projections.distinct(…
Miguel Ping
22
votes
2 answers

How do I write a MAX query with a where clause in JPA 2.0?

I'm using JPA 2.0. Hibernate 4.1.0.Final, and Java 6. How do I write a JPA query from the following psuedo-SQL? select max(e.dateProcessed) from Event e where e.org = myOrg And my domain object looks like the following: @GenericGenerator(name =…
Dave
  • 15,639
  • 133
  • 442
  • 830
21
votes
1 answer

Hibernate criteria projection distinct

Hi i want to write a query using criteria : The following query has to be created using criteria: "Select Distinct(s2Taxper) from S2 where s2Tc='601' AND s2Txcd!=''" thanks in advance
user1450954
  • 237
  • 1
  • 3
  • 10
20
votes
5 answers

Hibernate Criteria Limit mechanism?

Hibernate Criteria support provides a setMaxResults() method to limit the results returned from the db. I can't find any answer to this in their documentation - how is this implemented? Is it querying for the entire result set and then returning…
john
  • 203
  • 1
  • 2
  • 4
19
votes
2 answers

Grails/GORM "in" criteria

Is it possible to do an "in" criteria using the GORM criteria. I'm looking for the equivalent of the following SQL select * from Person where age in (20,21,22); If it was possible I guess the syntax would be something like: def results =…
Dónal
  • 185,044
  • 174
  • 569
  • 824
19
votes
4 answers

Subquery in select clause with JPA Criteria API

I'm trying, as in title, to insert a subquery in select clause like in this simple SQL: SELECT id, name, (select count(*) from item) from item this is obviously only a mock query just to make my point. (The point would be to get the last invoice…
lelmarir
  • 593
  • 2
  • 7
  • 24
18
votes
4 answers

Do you like the Criteria api of JPA 2.0? Do you use it with framework?

I'm used to work with Criteria API in Hibernate, and just watched how the Criteria in JPA 2.0 work. What i like most in the Criteria of Hibernate is the ease we have to compose with Criterions. The JPA Criteria seems quite heavy for me, and not as…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
18
votes
2 answers

using a ParameterExpression versus a variable in JPA Criteria API

When using the JPA Criteria API, what is the advantage of using a ParameterExpression over a variable directly? E.g. when I wish to search for a customer by name in a String variable, I could write something like private List
Henno Vermeulen
  • 1,495
  • 2
  • 15
  • 25
17
votes
1 answer

Hibernate: Criteria with many-to-many join table?

Consider the following two relations: @Entity class Foo { @Id id; @ManyToMany @JoinTable(name = "ATag", joinColumns = @JoinColumn(name = "foo_id"), inverseJoinColumns = @JoinColumn(name = "tag_id")) Set
Lenik
  • 13,946
  • 17
  • 75
  • 103
17
votes
1 answer

hibernate inner select in from clause

I'd like to know if it's possible to specify a select clause in a from clause something like select count(*) as Y, this_.NAME as A, sel2.C from TABLE1 this_, (select count(*) as C from (select this_.NAME, this_.SEX from…
Luca
  • 171
  • 1
  • 1
  • 4
17
votes
3 answers

Hibernate Criteria Order By

I have a table called Gift, which has a one-to-many relationship to a table called ClickThrough - which indicates how many times that particular Gift has been clicked. I need to query for all of the Gift objects, ordered by ClickThrough count. I do…
Dustin Wilhelmi
  • 1,769
  • 2
  • 13
  • 27
17
votes
1 answer

Complex queries with JPA Criteria builder

Can someone suggest me how to build up the following query using JPA Criteria builder API? SELECT id,status,created_at from transactions where status='1' and currency='USD' and appId='123' order by id It's better if I can find a solution which…
Aina Ari
  • 273
  • 2
  • 3
  • 6
16
votes
5 answers

Using hibernate criteria, is there a way to escape special characters?

For this question, we want to avoid having to write a special query since the query would have to be different across multiple databases. Using only hibernate criteria, we want to be able to escape special characters. This situation is the reason…
Kevin Crowell
  • 10,082
  • 4
  • 35
  • 51