hql

JasperReports JRBeanCollectionDataSource still confused...

So I do now have my working and filling reports. The users of my program can now pass objects from the program to a report object and fill it using the JRBeanCollectionDataSource and that does work. However I can't get all the data in the report I want. I am just very confused about this, how the fields that I declare with a name and...

HQL query equivalence: Why are them different

Hi I have a working HQL query which I want to optimize. It is as follows: select distinct A.id from Import as A, Place D where (A.place=D or A.placeBOK=D) and D.country=? I tried to replcae the query from above by the following: select distinct A.id from Import as A where A.place.country=? or A.placeBOK.country=? Besides performan...

datetime and timespan arithmetic in TSQL via HQL

I need to create an HQL where clause which has the form: where tbl1.DateTimeField + tbl2.TimeSpanField >= :someDateTimeParameter The DateTimeField is of type DateTime The TimeSpanField is of type BigInt (is this the best option?) The someDateTimeParameter is a DateTime writing the HQL query as above translates almost exactly into T...

HQL: group by month

Hi everyone, I'm trying to group by month some rows using HQL, but I'm kind of new to that API and can't seem to get it to work. Here is my code: Criteria query = getHibernateSession().createCriteria(SalesPerformance.class); // summary report is grouped by date query.setProjection(Projections.projectionList().add( ...

NHibernate query for matching all tags

Here are my relevant classes: public class Item { public virtual int Id { get; protected set; } public virtual IList<Tag> Tags { get; set; } } public class Tags { public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual IList<Item> Items { get; set; } } These are mapped...

Nhibernate Tag Cloud

Hi, I'm trying to get a Tag Cloud architecture working in NHibernate. public class Tag : Entity { public virtual int Id { get; set; } public virtual string Text { get; set; } } This table will map to a few entities in my schema so I don't want to add a collection to the Tag class for each association. I do however want to qu...

Proper way of writing a HQL in ( ... ) query

Assuming that I want to write the following HQL query: FROM Cat c WHERE c.id IN (1,2,3) what is the proper way of writing this as a parametrized query, e.g. FROM Cat c WHERE c.id IN (?) ...

How to lazy load a one-to-one composition via hql

If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B. The mapping is as follows: <class name="EntityA" table="TABLE_A" mutable="true" lazy="true"> <id name="idA" type="long" column="pk_a" unsaved-value="null"> <generator class="sequence"> <param name="sequence">pk_a_seq</param> ...

HQL Order by query giving problem

I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as ret_name, ret.id.retailerId as ret_id, ret.id.serviceId as service_id, (select count(distinct i.inspectionId) as inspections from Inspection i inner join i.c...

How to avoid hardcoded field names in HQL, Hibernate?

Suppose that I have the following HQL: String hql = "select e.aField from MyEntity as e"; If I want to refactor and change the name of the MyEntity's member variable aField to something else, I also have to change all occurrences in the whole code in Strings. If I forget to change one hql string the code breaks. How can I avoid this ...

Join without association in HQL

Lets say I have two tables(A, B) like: A {id, a, c} B {id, b, c} I have also their entities. I want to write an HQL so that the result set will be like (where A.c = B.c): (a1, b1, c1) (a2, b2, c2) (a3, b3, c3) ... Since on clauses are not supported by hibernate I am stuck and I don't know how to write the query. ...

hibernate query problem, so close and stumped...

The schema: (psuedocode) I have a bean, called BaseEntity... @Entity class BaseEntity { @OneToMany @CascadeType.ALL List [Property] properties; //the use angled braces ommited for the stackoverflow editor to show up properly } Property is another bean... @Entity class Property { @ManyToOne Category category; @OneToO...

Using HQL to query on a date while ignoring the time on Oracle

I have a table (in Oracle 9 and up) where I need to find all entries for a given day using Hibernate. The entries have timestamps (with data type 'date'). Some of the entries have a time, others only have a date. This can not be changed, as this is the output of other applications which I can not change. In SQL I would write something al...

What's wrong with this HQL? "No data type for node"

session.createQuery("Select attribute from GoodsSection tgs " + "join gs.ascendants ags join ags.attributes attribute " + "where attribute.outerId = :outerId and tgs = :section ") .setString("outerId", pOuterId) .setEntity("section", section) .setMaxResults(1) .uniqueResult(); Looks fine to me, but the result is java.lang.Ille...

JSF, Hibernate

Hi, I have a table called Items. When I tried to do 'Hibernate Reverse Enginering' in MyEclipse and run the program, I got this error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?tems0_.ItemID...

How to perform date operations in hibernate HQL

Hello friends, I want to perform data time operations using hibernate hql. I want to add and subtract two dates as well as I want to subtract 1 year or 1 month from a particular date. How is this possible using HQL in hibernate. Does anyone know about it? is there any tutorial available for this? Please help if you can. Thanks. ...

JPA/Hibernate: code based validation of jpa queries.

What is the right way do validate a jpa query programmatically. Hibernate validates all annotation based named queries on entities. But how can I call this validation routine on programmatically builded jpa queries, to check for errors? @Entity public class Foo { @Id public int id; public String name; } main(...) { Query q = ...

Hibernate dynamic instantiations with collections, is it possible?

I would like to write a hql query using a dynamic instantiation with a list as one of it's parameters. Simplified example: A HQL query with a dynamic instantiation: select new x.y.UserDto(u.name, u.contacts) from User u where u.xyz=:param1 ... and my dto class constructor is: public class UserDto { private String name; privat...

How to test HQL queries?

I'm searching for a fast (really fast) way to test changes to hibernate queries. I have a huge application with thousands of different HQL queries (in XML files) and 100+ mapped classes and i dont want to redeploy the whole application to just test one tiny change to a query. How would a good setup look like to free me from redeployment...

NHibernate:HQL: Remove time part from date field

I'm trying to group table values by date, and this HQL query works fine: SELECT af.SubmitedDate, COUNT (af.Id) FROM ApplicationForm af GROUP BY af.SubmitedDate The problem is that field af.SubmitedDate also contains time part, sine I'm using SQL Server 2005, so the grouping is done by date-time, not only by date. When I try to d...