Questions tagged [detachedcriteria]
189 questions
16
votes
2 answers
Hibernate criteria query with subquery joining two columns
I have a table, "Quote", mapped in hibernate that has a composite key of an integer id and a date, and several additional columns. I'd like to write a criteria query that uses a DetachedCriteria to get the row for each id with the greatest date.
In…

cha
- 207
- 1
- 2
- 9
15
votes
2 answers
Retrieving Polymorphic Hibernate Objects Using a Criteria Query
In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all.…

maxdj
- 427
- 2
- 5
- 15
9
votes
1 answer
Criteria subquery with not null
I want to convert the following subquery to use hibernate subquery:
getCurrentSession().createQuery("from Employee where id in (select adminId from Department where adminId is not null)")
…

Mahmoud Saleh
- 33,303
- 119
- 337
- 498
9
votes
1 answer
What's the difference between DetachedCriteria and ICriteria
These classes have some similar methods but seem to work slightly different.
What's the difference between them and when should I use each of them?

x__dos
- 1,813
- 3
- 27
- 47
8
votes
1 answer
Using Hibernate Criteria API, how to query for a subproperty of a property that exists only for certain property types
Consider classes Account, RealAccount, VirtualAccount, and Operation such that:
class Account { }
class RealAccount extends Account { String name; }
class VirtualAccount extends Account { }
class Operation { Account account; }
This means…

Marcelo Glasberg
- 29,013
- 23
- 109
- 133
8
votes
2 answers
Hibernate subquery detachedCriteria
How to write a subquery in hibernate which is having multiple subqueries. for example
select * from project_dtls where project_id in
(select project_id from project_users where user_id =
(select user_id from user_dtls where…

DebD
- 374
- 1
- 4
- 18
7
votes
1 answer
Eager fetching nested object with DetachedCriteria in Hibernate
I have to modify a large Hibernate DetachedCriteria query to fetch some additional associations.
My object graph resembles the structure below, I want to fetch the sales associated with each Car:
...
…

seanhodges
- 17,426
- 15
- 71
- 93
6
votes
2 answers
How can I express joining to a grouped subquery using NHibernate?
I'm trying to express a SQL query using NHibernate's Criteria API, and I'm running into difficulty because I'm thinking in a database-centric way while NHibernate is object-centric.
SQL (works great):
select outerT.id, outerT.col1, outerT.col2,…

David Rubin
- 1,610
- 1
- 17
- 28
6
votes
2 answers
Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria
I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this:
Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine");
criteria.add(Expression.eq("productLine.active",…

Gilean
- 14,708
- 10
- 45
- 52
5
votes
1 answer
Is this query possible using Criteria or DetachedCriteria Hibernate
The question is simple can this query be done in Hibernate using Criteria or DetachedCriteria? i guess not but i wanted to do this question maybe exist a workaround.
SELECT
COLUMNS
FROM table
WHERE id not in (
SELECT * FROM (
SELECT…

chiperortiz
- 4,751
- 9
- 45
- 79
5
votes
3 answers
Alias for properties that exist only in subclasses (Hibernate Criteria)
Consider the class Operation, and its 3 subclasses:
class Operation {}
class OpA extends Operation { }
class OpB extends Operation { Account account; }
class OpC extends Operation { Account account; }
Only OpB and OpC have a field called…

Marcelo Glasberg
- 29,013
- 23
- 109
- 133
4
votes
3 answers
I have expired problems with LikeExpression in hibernate(hibernate 3.5.5)
Looks like it does not work with ignorCase.
The first assert returns true. Second - false. Any Ideas?
EntityManager entityManager = (EntityManager) applicationContext.getBean("entityManager");
HibernateTemplate hibernateTemplate =…

user590444
- 4,252
- 8
- 36
- 43
4
votes
0 answers
grails 3.3 gorm where query with projection count() different than list().size()
According to the Gorm 6 documentation section 7.4 the Where Query returns a DetachedCriteria, which provides a method count() that is supposed to return the number of records returned by the query. In fact, as far as I can tell, if dc is an…

MonetsChemist
- 165
- 10
4
votes
0 answers
How should one use Where-Queries and DetachedCriteria in Grails?
EDIT1: I also accept answers that guide me in reusing DetachedCriteria without where queries. Where queries are my preference, but if regular DetachedCriteria is less hassle and more mature, I am willing to use it instead.
I've been trying to wrap…

nst1nctz
- 333
- 3
- 23
4
votes
1 answer
Hibernate Subquery and DetachedCriteria
I have created a DetachedCriteria that is retrieving estates that have the isApproved and isPublished set to true. It is defined in this way:
DetachedCriteria activePublishedCriteria = DetachedCriteria.forClass(Estate.class)
…

dawez
- 2,714
- 2
- 29
- 50