detachedcriteria

How do I serialize an NHibernate DetachedCriteria object?

I am looking for a solution to persist NHibernate DetachedCriteria objects to a database. I have tracked down the NHibernateUtil and the GetSerializable method, but I'm unsure how to use it to serialize a DetachedCriteria object. Any help on this would be greatly appreciated. Thank you. ...

Restrictions.Disjunction() between condition a AND condition b OR condition c AND condition d

How can I create a disjunction in NHibernate that would accomplish the following sql: Select * from MyTable Where (conditionA = true AND conditionB = true) OR (conditionC = true AND conditionD = true) From what I've seen, the Disjuntion() takes single criterions and "ORs" them together. Is it possible to group to criterion tog...

Nhibernate DetachedCriteria Left Outer Join on subquery

Hi! 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 _groupItemRestrictions_ There can be multiple GroupDefinitions, User can belong to ...

(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<DateTime, IValuation> Valuations { get; set; } } <class name="InternalFund"> <map name="Valuations"> <key> <column name="FundID" /> </key> <i...

NHibernate: Convert an ICriteria to a DetachedCriteria

Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using: .Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery)) Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference. ...

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 = DetachedCriteria.For(typeof(MyObject)); ProjectionList projectionList = Projections.ProjectionList(); ...

Nhibernate DetachedCriteria: Find entities where a property's property match a value

Hi, I have two following classes: public class User { public virtual Guid Id { get; set; } public virtual UserCredentials Credentials { get; set; } // other stuff protected User() { } } public class UserCredentials { public virtual Guid Id { get; set; } public virtual string UserName { get; set; } // oth...

Using a subselect in a join using NHibernate

I would like to write the following SQl in NHibernate - Detached Criteria if possible. select * from parent INNER JOIN child on parent.id=child.parentid INNER JOIN (select ChildID, MAX(ChildDate) MaxChildDate from child group by ChildID) max ON child.childid, child.ChildDate=max.MaxChildDate This gives me the latest child in ever...

NHibernate: getting multiple entities with subset of child collection?

Hello, My classes look something like this (I include only the relevant properties): public class Order { public virtual Customer Customer { get; set; } public virtual IEnumerable<OrderLine> OrderLines { get; set; } } public class OrderLine { public virtual string Product { get; set; } // Simplified } Now I What I want is...

Criteria query with restriction across a joined subclass problem

I have the following graph: OrderLine OrderLineExtension OrderLineExtensionA OrderLineExtensionB OrderLineExtensionC OrderLine contains a Set of OrderLineExtension. OrderLineExtension is defined as : @Inheritance(strategy = InheritanceType.JOINED) and is marked as an entity and is abstract A table is creat...

How do i create a Hibernate Criteria to order by some properties of collection

Say, i have an entity that has a history of operations as a collection. I want to sort entities by the date of the latest operation (it's the first element of history). i'd like to do something like this: criteria.addOrder(Order("history[0].date")) is this possible? ...

Castle ActiveRecord DetachedCriteria Performance For One To Many Criteria, or just use SubQuery.In

When querying into child collections should I be wary of performance and duplicate results which result from the use of CreateAlias("ChildCollectionName", "alias") would you think it would be better to just perform subqueries on Child Collections to get a big list of "parentId"s and then do an In clause on the parent. For Example clas...

NHibernate Lambda Extensions can't use any alias query on DetachedCriteria

I'm trying to write a simple query that requires an alias as it's a Many-To-Many assocation however I can't get it to work with NH Lambda Extensions. It always gives me a compile error even though as far as I can tell it's exactly the same as the documentation and all the examples I've seen online. Works var query = DetachedCriteria.Fo...

Problem using Hibernate Projections

Hello! I'm using Richfaces + HibernateQuery to create a data list. I'm trying to use Hibernate Projections to group my query result. Here is the code: final DetachedCriteria criteria = DetachedCriteria .forClass(Class.class, "c") .setProjection(Projections.projectionList() .add(Projections.groupProperty("c.id"))); .....

Hibernate Criteria: Add restrictions to Criteria and DetachedCriteria

Currently our queries add a variety of Restrictions to ensure the results are considered active or live. These Restrictions are used in several places/queries so a method was setup similar to public Criteria addStandardCriteria(Criteria criteria, ...) { // Add restrictions, create aliases based on parameters // and othe...

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", "Y")); DetachedCriteria subCriteria = DetachedCriteria.forClass(Model.class, "model"); subCr...

In NHibernate, how do I combine two DetachedCriteria instances

My scenario is this: I have a base NHibernate query to run of the form (I've coded it using DetachedCriteria , but describe it here using SQL syntax): SELECT * FROM Items I INNER JOIN SubItems S on S.FK = I.Key The user interface to show the results of this join allows the user to specify additional criteria: Say: I.SomeField = 'Use...

Using an interface for a subquery in NHibernate

I normally query interfaces using DetachedCriteria in NHibernate: DetachedCriteria crit = DetachedCriteria.For<IParent>(); And this works fine. I now want to create a subquery for a child object thus: DetachedCriteria subcrit = DetachedCriteria.For<IChild>(); and add it to the criteria like this (kind of, p.Child is actually an al...

Enum mapping and criteria

Hi, I have two entities: "Parent" & "Child" Child is mapped in Parent like this: Code: <many-to-one name="child" class="org.demo.Child" update="false" insert="false" embed-xml="false" node="chd/@id" > <column name="CHILD_ID" precision="10" scale="0" not-null="true" /> </many-to-one> and Child has an Enum type mapped ...

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) .add(Restrictions.eq("isApproved", true)) .add(Restrictions.eq("isPublished", true)) .setResultTransf...