hql

Pre loading objects in an HQL query

I'm using the following HQL query to try and load a set of objects when I select a Student object based on the advice found at the following link. http://www.javalobby.org/articles/hibernate-query-101/ from gradebook.model.Student student where student.studentId=1 left join fetch student.scores I get the following error. unexpected to...

Retrieving and loading third level refferenced classes through HQL

I have the following class setup for a Student in Hibernate. Class student contains a set of Score objects. Each score object contains the score, student id, and a gradeEvent object. A grade event object contains things such as date, description, etc. I want to fetch a student and load all there associated score objects and the gradeEven...

How to map an abstract class or interface in Hibernate HQL?

Imagine that I have a Debtor class. With Hibernate, I will define the class like that: @Entity @Table(name = "T_DEBTOR") public class Debtor { @Id @Column(name = "ID_DEBTOR") private String idDebtor; ... My DAO will then looks like: public class DebtorDaoImpl implements DebtorDao { @PersistenceContext privat...

hibernate many-to-many

Hi, i have three tables and 2 JPA model classes: Unit ------------ id [PK] - Integer code - String unitGroups - List<UnitGroup> UnitGroup ------------ id [PK] - Integer ugKey - String units - List<Unit> units and unitGroups have many-to-many relationship between themselves. briefly i want to write an HQL query...

Hibernate HQL: how to use a complex left join fetch

Hi all, I want to add a left join on TASK table when the following condition occurs: LEFT JOIN FETCH PROMPT p on (t.id = p.task.id and p.applicationName in ('XXX')) Here is my hql query: select distinct t from TASK t LEFT JOIN FETCH SERVER ser ...

EJB-QL Query List inside Object

I'm attempting to write what should be a simple (I hope) EJB-QL query. Here are my objects: public class Room { private String name; private List<RoomConfiguration> configs; } public class RoomConfiguration { private Integer capacity; private String name; } How can I search for rooms with a minimum capacity? A r...

Hibernate Join with OR clause

I'm trying to figure out how to generate a simple join that uses an 'or' clause contained within it, using HQL or Hibernate annotations. Here is an example of what I want the SQL to look like: select * from tableA left outer join tableB on tableA.id1 = tableB.id1 or tableA.id2 = tableB.id2 where ... I know I can do straight SQ...

NHibernate criteria datetime format issue

Hi I have a simple nHibernate criteria query which is looking for records with a datetime less than today: example: criteria.Add(Expression.Le("TheDate", DateTime.Today)); However, the results I am getting are incorrect when the day/month is ambiguous (eg 12th November 2009 returns the records for 11th December 2009) I have looked ...

How to get dummy column in hq uery in nhibernate?

Hi, How can i add a dummy column in HQL query. SQL : select Actualcolumn, 1 from Table In NHibernate How can I do that, I googled for this but I didn't find any solution. HQL: ? Thanks nRk ...

how to combine java.util.Calendar and HQL Between

I'm trying to get the books that were loaned between two dates. Since data has the lovely 2009 is shown as 109 feature I decided to use calendars. However when writing my HQL I ran into the problem that BETWEEN doesn't view a Calendar as a date. Now I'm wondering if there's a solution for this. Or am I stuck writing functions in my clas...

HQL: get a list where a join contains nulls

I have three objects. public class ParentClass { public virtual Guid ParentClassId { get; set; } public virtual IList<Child> Children { get; set; } } public class Child { public virtual Guid ChildId { get; set; } public virtual ParentClass Parent { get; set; } } public class Record { public virtual Guid RecordId { get; set; } public v...

Hibernate Second-Level Query Cache not working Eager Fetching

In NHibernate Profiler I observed that when I use eager fetching on an association, using "left join fetch" in an HQL Query or .SetFetchMode() in a Criteria Query the query no longer gets cached in the query cache. In fact from what I can see only very basic queries are cached. If anyone can give me some insight into what queries get c...

HQL with a collection in the WHERE clause

Hello good people! I've been trying for the this whole a query who is officially giving me nightmares. The system is a user and contact management. So I have UserAccount, Contact and Phone. UserAccount has a bidirectional one-to-many relationship with Contact and an unidirectional one on phone all mapped by a Set: //UserAccount ma...

Nhibernate ICriteria and Using Lambda Expressions in queries

hi i am new in NHibernate and i am a little confused. Suppose we have a product table. Let the product table have 2 columns price1 and price2. then i may query mapped product entities via HQL as follows: string queryString = @"from product p where p.price1 = p.price2 + 100 "; IList result = session.CreateQuery(queryString).List(); ...

Where are the NHibernate/Hibernate HQL and ICriteria query examples?

I'm still quite new to NHibernate and most of it I'm getting to grips with. One area that I'm really lacking a proper understanding of though is querying (at least when it comes to anything reasonably complex). I learn best by example, but I feel that I haven't really been able to find all that many in depth querying examples on the we...

HQL to SQL converter

Does anyone know how to convert NHibernate HQL to SQL Scripts? ...

Nhibernate - How to debug "Antlr.Runtime.NoViableAltException"?

With many HQL queries I am trying, time and time again I am getting this exception: Antlr.Runtime.NoViableAltException This is really generic and unhelpful - does anyone know how best to debug this? Obviously it's a problem with my HQL - but without any clue as to what exactly is wrong it's very much a case of trial and error. I'm p...

Hibernate: ORDER BY using Criteria API

Hi guys, When I write a HQL query Query q = session.createQuery("SELECT cat from Cat as cat ORDER BY cat.mother.kind.value"); return q.list(); Everything is fine. However, when I write a Criteria Criteria c = session.createCriteria(Cat.class); c.addOrder(Order.asc("mother.kind.value")); return c.list(); I get an exception org.hibe...

Hibernate queries slow down drastically after an entity is loaded in the session

I'm using Hibernate EntityManager, and am experiencing a weird slowdown in my Hibernate queries. Take a look at this code: public void testQuerySpeed() { for(int i = 0; i < 1000; i++) { em.createNativeQuery("SELECT 1").getResultList(); } } This runs in about 750ms on my machine. Not blazing fast considering it's just s...

Querying entities which have a specific collection entry using HQL

I have Item objects which have a collection of attributes defined as a map. Now I want to retrieve all objects which have a specific attribute (by name, locale and value) An expecert of the Item mapping: <map table="ITEM_ATTRIBUTES" name="attributes"> <key column="item_id" foreign-key="fk_itmr_attrbts_itmrs"/> <composite-index clas...