Questions tagged [createcriteria]

Creating criteria based queries with GORM, Hibernate or Grails

105 questions
2
votes
3 answers

nhibernate CreateCriteria wildcard Like when

In SQL I can write SELECT blah FROM Clients Where @p1 Like '%'+lastname+'%' How do I represent this with CreateCriteria in Nhibernate? I've tried s.CreateCriteria.Add(Restrictions.Where(c => "something".Contains(c.LastName)) but…
Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160
2
votes
1 answer

Grails sub query with createCriteria

I have sql query like below select transf, count(fname) from peak_info where fname in (select peakfile from pe_result where conid = 'GO:0006007' and fdr > 0.05) group by transf; which I want to implement in grails create criteria. Currently, I…
SnehalP
  • 69
  • 11
2
votes
1 answer

Cannot perform unit test with function which have createCriteria() statement

I want to write a unit test (by JUnit) to test value of this function in Groovy: String getPeopleNamesById(int[] peopleIds) { List names = People.createCriteria().list{ projections { property("name") } …
Đinh Hồng Châu
  • 5,300
  • 15
  • 53
  • 90
2
votes
1 answer

NHibernate CreateCriteria and CreateQuery generates different sql?

I'm new to NHibernate and can't figure out why these two statements generates different sql. the first one only get the ClientInformation (with Information and Client being Proxies) which is what i want. return repository …
2
votes
1 answer

Grails - createCriteria from if and else with null property

I am using Grails 2.3.4. I am trying to retrieve a domain object with specific criteria, however I have trouble getting around when the properties are null. Here is an example. class Domain1 { int locationId Domain2 domain2 Domain3 domain3 …
2
votes
2 answers

Grails createCriteria and using a Transient field and PagedResultsList

Domain Fields: startDate: Date length: Integer perpetuity: Boolean expiryDate: Transient (startDate + length (in years)) Domain methods - These methods are used for filtering on a big filter form for a user to search for the 4 different expiration…
Vaesive
  • 105
  • 1
  • 11
2
votes
3 answers

Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?

I have a problem similar to this. But I want a does not contain functionality. Like I have a Post domain. A Post hasMany User. What I'd like to do, using createCriteria, is something like this: def c = Post.createCriteria() def l = c.list (max:…
kishore
  • 127
  • 1
  • 13
2
votes
1 answer

CreateCriteria sorting on two columns combined

SELECT [quantity ] ,[price] FROM [dbo].[orderItem] ORDER BY (quantity * price) DESC How should I write a CreateCriteria to generate SQL like the example above?
2
votes
2 answers

CreateCriteria with projections does not select all columns

My Question is exactly like Grails Projections not returning all properties and not grouped I have a following criteria def sharedDocumentsInstanceList SharedDocuments.createCriteria().list(params){ createAlias('receiver', 'r') …
Sap
  • 5,197
  • 8
  • 59
  • 101
2
votes
1 answer

Explain the difference between CreateCriteria(typeof(Cat)) and CreateCriteria()

I've seen both formats in different examples, tutorials, blogs, etc, but for the life of me, I cannot find an explanation for the difference. What is the difference between ICriteria crit = session.CreateCriteria(typeof(Cat)); and ICriteria crit =…
Miaka
  • 63
  • 5
2
votes
1 answer

Grails: Use results of Criteria + projections as a filter on the original table

I have the following table/model: class Post { int id; String comment; static belongsTo = [category_id:Category]; } I wish to create a query that can filter out the last Post (highest id) per Category. I want the results in List
Chopo87
  • 1,240
  • 4
  • 19
  • 32
2
votes
1 answer

Hibernate createCriteria JOIN, ORDER, DISTINCT from one level

I have 3 classes: first, second, third I have createria approximately like this: First.createCriteria().listDistinct { if(....){fetchMode("second", FetchMode.JOIN) fetchMode("second.third", FetchMode.JOIN)} …
1
vote
2 answers

I am facing a problem with projections in createCriteria

I am facing a problem to get the required result from this closure def authors{ results = Message.createCriteria().list { projections { author{ groupProperty('id', 'authorId') // 2nd param is alias …
1
vote
1 answer

Can I select specific columns with Hibernate "createCriteria()"?

I used createCriteria() and setFetchMode() methods to join and select. I don't need all columns so I want to select specific columns to improve performance, but I can't find how to do it. Maybe should I use HQL instead?
Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
1
vote
1 answer

Grails CreateCriteria logical OR not working properly

I'm trying to perform a filter on a group of objects based on a "State" criteria. ... or { office { state { 'in'('abbrev', filters.stateFilter) } } state { 'in'('abbrev', filters.stateFilter) …
Vaesive
  • 105
  • 1
  • 11