criteria

Copy Selective Data from Database to Invoice, Based on Certain Criteria

For starters, here is an example of a microsoft excel database I am working with: Month/Address/Name/Description/Amount January/123 Street/Fred/Painting/100 January/456 Avenue/Scott/Flooring/400 January/789 Road/Scott/Plumbing/100 February/123 Street/Fred/Flooring/600 February/246 Lane/Fred/Electrical/300 March/789 Road/Scott/Drywall/15...

NHibernate: What are the options for fetching multiple entities in one query?

The NHibernate Book discusses very briefly queries that fetch several queries at the same time. They only show how to do this with the native CreateSQLQuery command. Are there any options for fetching multiple entities simultaneously using the criteria or hql APIs? ...

C++ struct sorting

I have a vector of custom Struct that needs to be sorted on different criteria each time Implementing operator < will allow only one criteria But I want to be able to specify sorting criteria each time I call C++ standard sort. How to do that? Please note it is better to be efficient in running time.. Thanks ...

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 ...

nHibernate Criteria for selecting a parent if a child in a collection ahs a specific value

If I have the following class structure what is the NH criteria to select a parent if one of it's children has a specific name? public class Child { public int Id { get; set; } public int Name { get; set; } } public class Parent { public int Id { get; set; } public IList<Child> Children { get; set; } } ...

Hibernate Criteria API - adding a criterion: string should be in collection

I have to following entity object @Entity public class Foobar { ... private List<String> uuids; ... } Now I'd like to make a criteria query which would fetch all Foobar pojos whose uuids list contains the string "abc123", I'm just not sure how to make the appropriate criterion. ...

How to write a Criteria Query when there's an <any> association

I'm having some trouble constructing the correct Criteria to do a particular query - after an afternoon of consultation with Professor Google, I'm hoping that someone can point me in the right direction. I have two entities of interest: OutputTsDef and NamedAttribute What I'm trying to do is to find all OutputTsDef that have a particul...

NHibernate Criteria Find by Id

Hello, I have 2 entities: public class Authority : Entity { [NotNull, NotEmpty] public virtual string Name { get; set; } [NotNull] public virtual AuthorityType Type { get; set; } } public class AuthorityType : Entity { [NotNull, NotEmpty] public virtual string Name { get; set; } public virtual string Des...

NHibernate Left Outer Join

I'm looking to create a Left outer join Nhibernate query with multiple on statements akin to this: SELECT * FROM [Database].[dbo].[Posts] p LEFT JOIN [Database].[dbo].[PostInteractions] i ON p.PostId = i.PostID_TargetPost And i.UserID_ActingUser = 202 I've been fooling around with the critera and aliases, but I haven't had a...

Write subquery in Criteria of nHibernate.

I read about subquery in Criteria, but I am still unable to grasp it properly. So, here I am taking one example and if somebody can help me writing that using subquery it will be great. Lets say we have table Employee{EmployeeId.(int),Name(string),Post(string),No_Of_years_working(int)} Now I want all the employees who are Managers a...

How do I setup a Criteria in nHibernate to query against multiple values

I want to query for a set of results based on the contents of a list, I've managed to do this for a single instance of the class Foo, but I'm unsure how I would do this for a IList<Foo>. So for a single instance of the class Foo, this works: public ICriteria CreateCriteria(Foo foo) { return session ...

nHibernate Criteria for selecting all entities with emtpy child collections

I'm having difficulty writing a Criteria to select all entities with empty child collections or empty grand-child collections. I can do these as seperate Criteria but I'm having trouble combining into a single Criteria. class structure: public class Component { public IList<Version> Versions { get; set; } } public ...

Need help optimizing a NHibernate criteria query that uses Restrictions.In(..)

I'm trying to figure out if there's a way I can do the following strictly using Criteria and DetachedCriteria via a subquery or some other way that is more optimal. NameGuidDto is nothing more than a lightweight object that has string and Guid properties. public IList<NameGuidDto> GetByManager(Employee manager) { // First, grab all ...

Hibernate Criteria API equivalent to HQL select clause?

I'd like to have a combined query for two persistent classes. In HQL this could be achieved by the select clause, select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr In the above example, Family is a conbined class with DemesticCat as its c...

How to query flags stored as enum in NHibernate

How to do either a HQL or a Criteria search (the latter is preferred) involving an enum that is used as flags. In other words, I have a persisted enum property that stores some kind of flags. I want to query all the records that have one of these flags set. Using Eq won't work of course because that will only be true, if that is the only...

Nhibernate Criteria Query with Join

I am looking to do the following using an NHibernate Criteria Query I have "Product"s which has 0 to Many "Media"s A product can be associated with 1 to Many ProductCategories These use a table in the middled to create the join ProductCategories Id Title ProductsProductCategories ProductCategoryId ProductId Produ...

nHibernate criteria - how do I implement 'having count'

I have the following table structure and I want a turn the query into a NH criteria but I'm not sure how to incorporate the correct 'Projection', does anyone know how? And the query I want to turn into a Criteria: select ComponentId from Table_1 where [Name] = 'Contact' or [Name] = 'CurrencyPair' group by ComponentId having count(Ver...

How does hibernate use an empty string for an equality restriction?

I have a column that potentially has some bad data and I can't clean it up, so I need to check for either null or empty string. I'm doing a Hibernate Criteria query so I've got the following that returns incorrectly right now: Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Criteria myC...

Customizing Hibernate Criteria - Adding conditions to a left join

I need to be able to do the following: Select * from Table1 left join Table2 on id1 = id2 AND i1 = ? Hibernate criteria doesn't allow be to specify the i1 = ? part. The existing code is using hibernate criteria and it would be a huge refactor to swap out for HQL Does anybody have any tips how I could implement this differently or ...

Size of assosiation in Hibernate criteria.

Hello guys. I've faced with a problem when querying with Hibernate Criteria in Grails. Take a look: def visitors = Client.withCriteria{ visits{ use ( TimeCategory ) {between('date',date,date+1.month-1)} } sizeGe("visits",params.from) sizeLe("visits",params.to) fetchMode("v...