Questions tagged [nhibernate-criteria]

The NHibernate Criteria API allows performing dynamic, object oriented queries in NHibernate.

Using the criteria API is one way to perform queries in NHibernate. Its strength is on writing dynamic queries at runtime. It lacks some features compared to HQL, for instance creation of cross products and joining objects on arbitrary properties.

Related:

  • QueryOver is a successor of Criteria, which provides more type safety at compile time, but is still base on Criteria.
  • Linq To NHibernate once based on Criteria, but had been rewritten to use HQL in later versions.

References:

286 questions
1
vote
2 answers

NHibernate FetchMode Cartesian Product

In my object graph, VendorServiceRateChange has a lazy loaded property IList VendorServiceList and the VendorService has a lazy loaded property IList. When I run the following code I get a Cartesian product between my…
rie819
  • 1,249
  • 12
  • 19
1
vote
1 answer

How create nhibernate criteria with inlaid terms in algorithm?

For example: var Ex1 = Expression.Eq("DocAttrId", new decimal(-2)); var Ex2 = Expression.Eq("RowPos", new decimal(1)); var Ex3 = Expression.Eq("DocAttrId", new decimal(105510)); var Ex4 = Expression.Eq("DocAttrId", new decimal(-1)); var ExGroup1 =…
Darien Fawkes
  • 3,023
  • 7
  • 24
  • 35
1
vote
1 answer

How do Specifications with Spring Data JPA really work?

For example, I have helper class with Specifications. Here is the example of one: public static Specification filterByName(String name) { return ((root, query, criteriaBuilder) -> name == null ? null : …
1
vote
1 answer

Help with conditional projection queries

I have a requirement wherein I need to display a list of employees and their roles. So if the role of the employee is Accounting, I want to display FirstName and LastName of that employee. Below is my code for it SearchTemplate RoleTemplate = new…
appuser
  • 269
  • 1
  • 3
  • 10
1
vote
1 answer

Error when using AliasToBeanResultTransformer in Criterion

I am trying to do some paging together with some fetching, but the result returns duplicates. I have therefore added a AliasToBeanResultTransformer, but then I get the following error: Could not find a setter for property 'this' in class…
Dofs
  • 17,737
  • 28
  • 75
  • 123
1
vote
2 answers

nhibernate criteria projection results in inefficient queries

Please see the following example which is a very simplified version of my code: Dim Criteria = Session.CreateCriteria(Of Person)() Criteria.SetProjection(Projections.Property("Car")) return Criteria.List(Of Car)() This works perfectly, however…
Richard
  • 1,289
  • 12
  • 25
1
vote
1 answer

How can I get count from joined query - criteria builder

I have a Entity Policy public class Policy extends BaseEntity { private Long id; private String policyNumber; ...... @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @OrderBy(value = "id") @JoinColumn(name = "policyID") @Where(clause…
Irakli
  • 973
  • 3
  • 19
  • 45
1
vote
2 answers

How do I create this query using NHibernate Criteria

I'm new to NHibernate, and I'm having trouble figuring out the best way to represent some SQL using NHibernate's Criteria engine. Here's a basic depiction of the object model: public class Project : EntityBase { // Properties for a…
Josh Anderson
  • 5,975
  • 2
  • 35
  • 48
1
vote
1 answer

How to truncate a float value in NHibernate Criteria Query?

We have a value stored in our database. This value is of data type float. Our application uses NHibernate Criteria to query the database. When querying this value, we want to filter on a value, say 66.66. The database will contain the value…
Matt
  • 317
  • 1
  • 2
  • 12
1
vote
1 answer

NHibernate - Help with ICriteria

I'm trying to convert the following SQL query to an ICriteria in NHibernate. SELECT DISTINCT m.typeId, t.typeName FROM Models m, Types t WHERE m.qualifier=? AND m.typeId IS NOT NULL AND m.typeId = t.typeId These are both mapped in NHibernate in…
Sam
  • 4,219
  • 7
  • 52
  • 80
1
vote
1 answer

nhibernate NamedQuery from criteriaQuery --> help needed

I am trying to convert a working criteria query into a named query, and not getting the syntax right. The hql version apparently wants both the type and id params specified. The query is over a class mapped with ANY (below also) Can someone give me…
Berryl
  • 12,471
  • 22
  • 98
  • 182
1
vote
1 answer

NHibernate query returning unmapped object using Criteria-api

I want to query an nhibernate mapped class but the result should be an unmapped object. The mapped and unmapped classes look like this: [Class(NameType = typeof(ClassA)] public class ClassA { [Cache(0, Usage = CacheUsage.ReadWrite)] [Id(1,…
Rian Schmits
  • 3,096
  • 3
  • 28
  • 44
1
vote
1 answer

DetachedCriteria equivalent needed

I need the DetachedCriteria equivalent to the following HQL: select obj from Objects obj, Text text where obj.TextId = text.TextId and order by text.Value Thanx
Apolo
  • 13
  • 2
1
vote
1 answer

When using CreateCriteria how do you sort the results in random order?

I have a function that returns a max number of items that are active. I would like to be able to make the returned results be sorted in random order. public IList GetWidgetsToDisplay(int maxToGet) { var query =…
1
vote
2 answers

NHibernate Criteria query on in-memory collection of entities

I would like to apply a Criteria query to an in-memory collection of entities, instead of on the database. Is this possible? To have Criteria API work like LINQ? Or alternatively, convert Criteria query to LINQ query. Thanks!
Jacko
  • 12,665
  • 18
  • 75
  • 126