criteria

NHibernate Criteria select items by the group by and sum of itemid within another table.

public class SearchText { public virtual int Id { get; set; } public virtual string Text { get; set; } } public class SearchTextLog { public virtual int Id { get; set; } public virtual SearchText SearchText { get; set; } public virtual User User { get; set; } public virtual int SearchCount { get; set; } publi...

NHIbernate OR Criteria Query

I have the following mapped classes Trade { ID, AccountFrom, AccountTo } Account {ID, Company} Company {ID} Now I cannot figure out a way select all trades where AccountFrom.Company.ID = X OR AccountTo.Company.ID = X I can get AND to work using the following: criteria.CreateCriteria("AccountFrom").CreateCriteria("Company").Add(Res...

NHibernate criteria API - how do I add a clause to compare one date to another date minus a value

I'm trying to build a criteria object using NHibernate that will compare date1 to date2 minus a value. In Sql Server I'd do this: select * from table where date1 < DateAdd(Day, 2, date2) Can anyone tell how I would do this in NHibernate? Cheers EDIT I should have specified this earlier, I'd like to find out how do do this using the ...

Hibernate queryCount with a condition

Hello, I'd like to make an hibernate query. My old query was like : public int getPublicationCountVote(Publication pub,Boolean voteType){ return HibernateUtil.queryCount(SocialVote.class , new String [] {VOTED_PUBLICATION_ID_FIELD, FOR_OR_AGAINST_FIELD} , new Object [] { pub.getId() , voteType }); } But now, ...

Hibernate criteria/filtering - only return elements in collection that are specified in the criteria

Hi, I have four hibernate classes: Trader, Legal, Party and Relation. Trader and Legal are types of party so extend it. A Trader can be related to a legal, a trader can be related to a trader and a legal to a legal. Both types can b the child or parent in the relationship. These relationhips are maintained in the Relation class. Both...

Complex Nhibernate Query using Criteria

Can someone put this into Nhibernate Criteria ? select u.* from dbo.tblPunch p inner join tblUsager u on u.USAGER_CODE = p.userId inner join ( select distinct(userId), max(datecreation) as DateLastPunch from dbo.tblPunch where ServiceId = 76629 group by userId ) lastPunch on p.userId = lastPunch.UserId and p.DateCreation = lastPunch.Da...

Is it possible to search for same value on multiple columns with Hibernate Criteria?

I have search query that has many optional parameters and then search word field that searches many columns. Is it possible to use hibernate criteria for this purpose? I need to search many columns with same search word. Example code (what is not working correctly) if(isNotEmpty(searchWord)) { criteria.add(Restrictions.like("descri...

Rounding up a free text date field, for use a 'Date To' criteria field

Hi, I've found that the Date.TryParse is pretty lenient on input - so skipping out the day or month will still return a value, though always floor rounded. E.g.: DateTime.TryParse("2010", out testDate) -> 01 Jan 2010 or DateTime.TryParse("may 2010", out testDate) -> 01 May 2010 I'd like to allow the user to input a date to be used...

How do I strongly type criteria when using NHibernate's CreateCriteria method?

I'm currently using NHibernate, for the first time, with Fluent NHibernate. I've gotten everything setup nicely, however now I've come to actual doing some data retrieval, it seems to have fallen short. I was expecting NHibernate, to allow me to do something like: session.CreateCriteria<TblDocket>() .Add(Restrictions.Eq(x=> x.Docke...

NHibernate: projecting a subclass type of an entity

How do I query a class of a specific entity in NHibernate? I basically want a projection that returns a System.Type of each row that matches criteria. I have looked at http://stackoverflow.com/questions/2787498/get-subclass-type-from-projection-with-nhibernate however when I create Projections.Property("alias.class") or Projections.Pr...

Hibernate criteria difficult query

I am trying to assemble a query using hibernate criteria. In my db, there is a [Game] table, a [Tag] table, and a many-to-many relationship modelled using a join table called [GameTag], which contains a game_id field and a tag_id field. My input is a list of tags (or tag_ids), and I would like to retrieve all games having all of these ...

[hibernate] SELECT AVG("...") with Criteria API

Hello, I'm having difficulties with translating following SQL syntax into Criteria API: SELECT AVG(dbo.Member.Points) FROM dbo.Member WHERE dbo.Member.PaidMemberRegDate IS NOT NULL; I have a Member class with a Points property. I just want to get the average Points of all Members that have the property PaidMemberRegDate set to null. ...

How to get Torque Criteria to use table aliases

Hey, I'm trying to create a query where I reference a table twice. I know how to do this in sql. It looks like this: SELECT t1.* FROM Table1 t1 LEFT JOIN Table1 t2 ON t1.ID = t2.OwnerID WHERE t1.Column1='ok' AND (t1.OwnerID = 0 OR t2.Column1='ok'); This will return all the elements of the table that are "ok" and ...

Collection property and Projections of Criteria API (Hibernate)

I have two entities that relate to each other as "many-to-one". So one type of the entity has a collection of child entities of another type. Is it possible to retrieve that collection property with Projections? I mean smth like criteria.setProjection( Projections.projectionList() .add( Projections.id() ) .add( Property.forName( "name"...

How can i perform this query in NHibernate for getting child count

select name, (select count(*) from products where products.category_Id=categories.Id) as productCount from categories session.CreateCriteria<Category>() but whats next? i don't even know how to search it in Google? ...

Why is Grails not returning what I'm looking for?

Here's the domain classes I'm working with: class Foo { String name, type static hasMany = [ bars: Bar ] List bars static mapping = { bars lazy:false } } class Bar { String value static belongsTo = Foo } I've written some Criteria queries in order to give the users an interface to que...

nhibernate criteria - table name has double quotes

Hello, I am using Fluent NHibernate in my application. I have a criteria query that looks like this - var query = DetachedCriteria .For<table2>() .SetProjection(Projections.Distinct(Projections.Property("id"))) //.Add(Restrictions.Between("date_field", startDate, endDate)) ...

More condition on hibernate left join clause

How to achieve subquery in hibernate criteria left join? I tried in this way, DetachedCriteria subquery = DetachedCriteria.forClass( Comment.class, "comment").add(Restrictions.eq("comment.divisionId", divisionId)); subquery.setProjection(Projections .groupProperty("comment.commentId")); Session ses...

Nhibernate Criteria/SQL Query problem

Hi I have a querry that returns a large number of rows. I want to know if there is a way to decrease query time without changing the results. One smsblast contains multiple smsresponses and smsresponse contains multiple smsstatuses. Variables status = int smsBlastId = int var queryStatus = DetachedCriteria.For<SmsStatus>() .Add(Re...

How can I retrieve a collection property using criteria Api

I want to retrieve a collection property using criteria public class A { private Collection<B> property // getters and setters } public class B { private int status // getters and setters } My criteria code is as follows: Criteria cr = getSession().createCriteria(A.class) cr.createA...