Questions tagged [detachedcriteria]

189 questions
2
votes
1 answer

NHibernate: getting multiple entities with subset of child collection?

My classes look something like this (I include only the relevant properties): public class Order { public virtual Customer Customer { get; set; } public virtual IEnumerable OrderLines { get; set; } } public class OrderLine { …
Morten Jacobsen
  • 986
  • 1
  • 11
  • 31
2
votes
1 answer

Filtering NHibernate SubType with ICriterion

Is there any way I can filter my NHibernate query on the SubType field before I hit the database by adding an ICriterion to my executing DetachedCriteria? My code looks something like this: DetachedCriteria detachedCriteria =…
Michael
  • 3,099
  • 4
  • 31
  • 40
2
votes
1 answer

How do I use a in clause 'in' a grails.gorm.DetachedCriteria?

Is it possible to use an 'in' criteria in a Grails DetachedCriteria? This is what I have, def query = new DetachedCriteria(DomainObject) // list is actually built up from another query, // but for this example I will use a predefined…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
2
votes
0 answers

Using Criteria for sub-queries

I have two tables in my Database, Tuser and TCompany, where Tuser : id | name | email Tcompany : id | companyName | userId where userId is foregn key of Tuser table. I have written a query to get all users whose name start with a …
Abhishek
  • 1,999
  • 5
  • 26
  • 52
2
votes
1 answer

(Detached)Criteria equivalent for HQL's 'index' function

I have an IDictionary on an object which I'm loading with the following mapping: public class InternalFund : IInternalFund { public virtual IDictionary Valuations { get; set; } }
Stu
  • 2,426
  • 2
  • 26
  • 42
2
votes
1 answer

Nhibernate DetachedCriteria Left Outer Join on subquery

I'll only try to present the main part of the problem, because the whole situation is much more complicated - I am unable to achieve the following with DetachedCriteria SELECT * FROM User LEFT OUTER JOIN GroupItem ON User.ID = GroupItem.UserID AND…
doblak
  • 3,036
  • 1
  • 27
  • 22
2
votes
1 answer

using detachedCriteria as a subquery for in clause

I am trying to use a detached criteria as subquery for 'in' clause but somehow it does not work: def trades = new DetachedCriteria(Trade).build { projections { property "tradeNbr" } } def activities = Activiies.withCriteria { …
rks
  • 451
  • 1
  • 8
  • 16
2
votes
1 answer

How dangerous is a compact anti-pattern, DetachedCriteria based, DAO utilitary for hibernate?

Long time ago I created an one-class-hibernate-util to ease my life on really really small applications using DetachedCriteria, as follows: import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import…
user985358
2
votes
2 answers

Join tables hibernate + group by

I need to do this query with Java + Hibernate. SELECT table2.id, COUNT(table2.id) AS count FROM table1 JOIN table2 ON table1.fk_tb2 = table2.id --many2one GROUP BY table2.id I would use DetachedCriteria class.....how can…
enfix
  • 6,680
  • 12
  • 55
  • 80
1
vote
0 answers

Grouping with DetachedCriteria without column selection

How to make grouping without selecting the column? detachedCriteria.setProjection(Projections.groupProperty("col1")); OR detachedCriteria.setProjection(Projections.sqlGroupProjection("col1", "col1", new String[]{}, new Type[]…
Astrid
  • 11
  • 4
1
vote
2 answers

Grails : from HQL to DetachedCriteria Query

Let say I have the following domain model : class Book { String title Set authors static hasMany = {authors: Author} } class Author { String name } The HQL query to retrieve a collection of Author given a query on a title…
Jean-Baptiste
  • 387
  • 3
  • 11
1
vote
1 answer

NHibernate SetFetchMode doesn't work with nested criteria

Assuming I run the following code: var placementCriteria = DetachedCriteria.For(); placementCriteria.Add(Restrictions.Le("StartDate", effectiveDate)); placementCriteria.Add(Restrictions.Ge("EndDate",…
rie819
  • 1,249
  • 12
  • 19
1
vote
0 answers

Querying Hibernate Parent/Child with Subquery Criteria

EDIT: relevant: https://forum.hibernate.org/viewtopic.php?f=1&t=946236&start=0 but still no solution there. I have a parent/child relationship. The parent maps a set of string tags. The simplified DDL: CREATE TABLE PARENT ( ID …
zenocon
  • 1,597
  • 1
  • 17
  • 24
1
vote
1 answer

Filter contents of lazy-loaded collection with NHibernate

I have a domain model that includes something like this: public class Customer : EntityBase, IAggregateRoot { public IList Comments { get; set; } } public class Comment : EntityBase { public User CreatedBy { get;…
Josh Anderson
  • 5,975
  • 2
  • 35
  • 48
1
vote
2 answers

How to write Hibernate query for collections Set

I have following Entity @Entity public class Employee{ private Integer id; private String name; private String address; private Date created; @OneToMany(mappedBy = "employee") private Set languages = new…
Anupam Gupta
  • 1,591
  • 8
  • 36
  • 60
1 2
3
12 13