hibernate-criteria

Query the other way across a one-to-many with Criteria Builder

Lets say I have the following one-to-many relationship: Site has many Users User belongs to one Site I've setup the relationship like this class Site { static hasMany = [users:User] ... } and class User { static belongsTo = [site:Site] int number String username ... } Basically I want to update the userna...

Nhibernate: distinct results in second level Collection

I have an object model like this: class EntityA { ... IList<EntityB> BList; ... } class EntityB { ... IList<EntityC> CList; } I have to fetch all the colelctions (Blist in EntityA and CList in EntityB), because if they all will be needed to make some operations, if i don't eager...

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

Grails: Problem with nested associations in criteria builder

I have a frustrating problem with the criteria builder. I have an application in which one user has one calendar, and a calendar has many entries. Seems straightforward enough, but when I try to get the calendar entries for a given user, I can't access the user property (MissingMethodException). Here's the code: def getEntries(User user...

Hibernate criteria -- alias

Hello, I'm struggling a bit with the concept of alias in Hibernate. My situation is the following: Order @OneToMany(cascade=CascadeType.ALL,mappedBy="m_order") private Set<OrderDetail> m_details; OrderDetail @ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="product_id") private Product m_product; @ManyToOne(casca...

Select all entities of exact class, but not derived from it using NHibernate Criteria API

I have two classes: Cat and DomesticCat, that extends Cat. I want to select all Cats, but no oneDomesticCat. How to do it using NHibernate criteria API? ...

Query Subset of Columns with Gorm

Suppose I have the following Domain class: class Book { String title String author byte[] largeCoverArtImage } I have a list view where I do not need to display largeCoverArtImage, how can I perform the following SQL query using GORM Criteria? select title, author from Book ...

how to make the criteria list returns 0 if nothing is added

How do you cause the criteria.list() to return 0 if nothing is "added" to the hibernate criteria? (The criteria returns all entries in the table.) ...

cannot resolve property when criteria refers to a embedded property.

I seem to be unable to create a query with a criterion which refers to a property inside a Embedded class. When i use "entity.embedded.property" it fails. If i create an alias of "entity.embedded.property" to itself the query works...Any tipes will be appreciated... ...

Is it possible to set aliases to a property within an Embedded as part of a Criteria ?

This is a general purpose question but from my experiences it does not appear to be possible to reference a property belonging to a embedded class within another. Directory Directory parent. Name // embedded String name; i cant seem to be able to create a Query that does find a directory where parent of parent's name is somet...

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

Hibernate annotations

Hi, I created a table in MySQL: 'object_label' with columns 'id' and 'name'. I inserted values to this table. In java I created new class -'ObjectLabel': import javax.persistence.*; @Entity @Table(name = "object_label") public class ObjectLabel implements Serializable { private static final long serialVersionUID =...

How to get over limitations of the Hibernate Criteria and Example APIs?

I'm in a position where our company has a database search service that is highly configurable, for which it's very useful to configure queries in a programmatic fashion. The Criteria API is powerful but when one of our developers refactors one of the data objects, the criteria restrictions won't signal that they're broken until we run ou...

Hibernate Criteria Projection

Well as the question says, i am trying to make a projection criteria querying only couple of the table attributes. So I have a Person Table/class and it has about 40 attributes i want my criteria to get dynamical number of attributes, lets say 10, 11 or 12.(sql terms "select firstname, lastname from person") and i was doing it like this ...

groovy / grails / unit testing / createCriteria.get

I can mock calls to: MyDomainClass.createCriteria().list{ eq('id',id) eq('anotherParameter',anotherParameterId) } with: def myCriteria = [ list : {Closure cls -> returnThisObject} ] MyDomainClass.metaClass.static.createCriteria = { myCriteria } as advised at: http://davistechyinfo.blogspot.com/2010/01/mocking-hibernat...

Combine NamedQuery and Criteria in Hibernate

I use Hibernate in a storefinder application. For the proximity search in SQL I use the haversine formula. Because this is a bit messy SQL I created a named SQL query in my .hbm.xml File for this. SELECT location.*, ( 3959 * acos( cos( radians(7.4481481) ) * cos( radians( X(location.coordinates) ) ) * cos( radians( ...

Grails (Hibernate) Criteria query

Hi, I have a domain class in my Grails app that looks like this: class Event { Date date } I want to write a criteria query that selects events that occurred in a certain month of a certain year, any suggestions? Thanks, Don ...

Groovy criteria query

Hi, I have a domain model that looks like this Category 1 ------- * Type 1 ------- * Expense Or in English "An expense has a type, and each type belongs to a category". I want to write a Criteria query that will find all expenses in a particular category. I tried both this Expense.withCriteria { eq('type.category', someCategoryI...

Null list returned from hibernate query with embedded id

I have an entity with an embedded key. The entity has only the key as a field and the key has 7 fields, some of which can be null. When I run the following query: Criteria criteria = session.createCriteria(getPersistentClass()); criteria.add(Restrictions.eq("id.profPropertyId", profileExtensionName)); Object obj = criteria.list(); log...

Can't create grails Criteria query containing a belongsTo relation

Hi all, I've been trying to create a criteria builder containing a belongsTo relation and have yet to succeed. Consider the following model: class Msg { ... static belongsTo = [user: User] ... } class User { ... Organisation organisation ... } I'm trying to make the following query: Msg.createCriteria()....