hql

Optional parameters with named query in Hibernate?

Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate? I'm using a native SQL query, but the question is probably applicable to named HQL queries as well. I'm pretty sure the answer to this is 'no', but I haven'...

HQL multiple updates. Is there a better way?

I have a Map, that I want to persist. The domain object is something like this: public class Settings { private String key; private String value; public String getKey() { ... } public String getValue() { ... } public void setKey(String key) { ... } public void setValue(String value) { ... } } The standard appr...

setfirstresult & setmaxresult in child collection

I have and entity lets call it Entity, and a Child collection Children. I have a screen where the user has the Entity information, and a list with the Children collection, but that collection can be get very big, so i was thinking about using paging: get the first 20 elements, and lazy load the next only if the user explicitly presses t...

NHibernate HQL date functions

I'm writing a notification platform using C# and NHibernate. I'm having difficulties with my queries. I have a Customer entity - which contains an AssessmentCompleted Property. A notification should be sent out 21 months after certification. So my query needs to include all customers where their AssessmentCompletedDate + 21months < curr...

Hibernate. Convert HQL to Criteria API

How to convert the following hql to Criteria API var criteria = this.Session.CreateQuery("select m, m.Attachments.size from AdvanceMessage m"); ? Thanks ...

HQL updates and domain objects

I have what may be a pretty elementary Hibernate question. Do HQL (and/or Criteria) update queries cause updates to live domain objects? And do they automatically flush now-invalid domain objects from the first-level cache? Example: Player playerReference1 = session.get(Player.class,1); session.createQuery("update players set gold = ...

How to query across many-to-many association in NHibernate?

I have two entities, Post and Tag. The Post entity has a collection of Tags which represents a many-to-many join between the two (that is, each post can have any number of tags and each tag can be associated with any number of posts). I am trying to retrieve all Posts which have a given tag. However, I seem to be unable to get this quer...

How to I create an HQL query to return objects in a many to many relationship?

Hi there. I have an application that includes 2 classes Club and Article. These are mapped in Hibernate as a many to many relationship. As a result, hibernate has created a table called CLUB_ARTICLE which it uses to manage the many to many relation ship. The CLUB and ARTILCE tables have no direct reference to each other and the mapping ...

HQL recursion, how do I do this?

Hi guys, I have a tree structure where each Node has a parent and a Set<Node> children. Each Node has a String title, and I want to make a query where I select Set<String> titles, being the title of this node and of all parent nodes. How do I write this query? The query for a single title is this, but like I said, I'd like it expanded ...

Select columns from join table only without requiring a join

Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key (Id) ) create table Items ( Id INT IDENTITY NOT NULL, primary key (Id) ) create table OrdersItems ( OrderId INT not null, ItemId INT not null, primary key (OrderId, ItemId) ) Is it possible to use HQL/criteria API to contruct a query...

Working with Hibernate Queries

I am new to hibernate queries, and trying to get a grasp on how everything works. I am using Hibernate 3 with Netbeans 6.5. I have a basic project set up and have been playing around with how to do everything. I started with essentially a search query. Where the user can enter values into one or more fields. The table would be Person ...

Grails: Help with HQL query.

I'm not very good in SQL and HQL... I have two domains: class Hotel { String name } class Room { Hotel hotel float price } How many hotels have at least one room ? ...

Using nhibernate <loader> element with HQL queries

Hi All I'm attempting to use an HQL query in a <loader> element to load an entity based on other entities. My class is as follows public class ParentOnly { public ParentOnly(){} public virtual int Id { get; set; } public virtual string ParentObjectName { get; set; } } and the mapping looks like this <class name="ParentO...

CF9 HQL Statement for many-to-many and Multiple Criteria

I have the following setup: Listing.cfc component persistent="true" { property name="ListingId" column="ListingId" type="numeric" ormtype="int" fieldtype="id" generator="identity"; ... property name="Features" type="array" hint="Array of features" singularname="Feature" fieldtype="many-to-many" cfc="Feature" linktable=...

How to implement paging in NHibernate with a left join query

I have an NHibernate query that looks like this: var query = Session.CreateQuery(@" select o from Order o left join o.Products p where (o.CompanyId = :companyId) AND (p.Status = :processing) order by o.UpdatedOn desc") ...

Hibernate Collection chaining

I have two Entities University courses Course students i want to access all the students in a university. I tried the following query select u.courses.students from university u i got the following exception. org.hibernate.QueryException: illegal attempt to dereference collection [university0_.id.courses] with element p...

How to order records by a computed column in Criteria API?

How can I write the below HQL query using the Criteria API? select s.Name, sum(q.PointsObtained), sum(q.TotalPoints) from Student s join s.Quizzes q group by s.Name order by (sum(q.PointsObtained) / sum(q.TotalPoints)) desc ...

Problem in HQL query

I written a query in my sql like this: "select * from table_name order by col_name = 101 desc " Which is working perfectly fine in mysql but when I tried to convert this query into HQl query then it is throwing an exception.So can anyone suggest me that how to write HQL query for the above SQL query. ...

how to find difference between two timestamp using hibernate query language

Hello I am trying to write an hql query which gives me the number of hours between two timestamp. So, far i am unable to do this. I have used hql hour function but that does not work if the timestamp corresponds to different date. Please provide any input. My hql query is select count(*) from com.xxx.Request as request where re...

Are Hibernate named HQL queries (in annotations) optimised?

A new colleague has just suggested using named HQL queries in Hibernate with annotations (i.e. @NamedQuery) instead of embedding HQL in our XxxxRepository classes. What I'd like to know is whether using the annotation provides any advantage except for centralising quueries? In particular, is there some performances gain, for instance ...