hql

Using hibernate/hql to truncate a table?

What is the recommended way to truncate a table using hibernate/hql? I've tried this: Query query = session.createQuery("truncate table MyTable"); query.executeUpdate(); But it didn't work (truncate doesn't seem do be documented anywhere in hql...) ...

HQL: order by property of nullable property

Assuming two tables, A[a_id, b_id] and B[b_id,c]. I need to execute the HQL query of form "From A a ORDER BY a.b.c", while b is nullable in class A. The query,however, returns only instances of A which have non-null b property. This happens because Hibernate generates SQL of form "SELECT FROM A,B WHERE A.b_id = B.b_id ORDER BY B.c" Wh...

hibernate&hql help

hello, i try to make a gui for some queries i work with netbeans and mysql and i have for example a student table with 6 fields age,id,year,... when i type the query: from Students it shows all the fields of the table and all data perfectly when i type a query like select year from Students I got a table but not with the year field ...

NHibernate HQL logic problem

Hi I'm trying to write an NHibernate HQL query that makes use of parenthesis in the where clause. However, the HQL parser seems to be ignoring my parenthesis, thus changing the meaning of my statement. Can anyone shed any light on the matter? The following HQL query: from WebUser u left join fetch u.WebUserProfile left join fetch...

Bidirectional HQL Query with NHibernate

I'm fairly new to HQL / NHibernate so this may be a bit of an amateurish question. Basically I have a bidirectional many-to-one association. In my query, I am trying to find all of the “parent” entities that contain “children” that match a certain criteria. I really don’t want to run the first query on the children and then query the p...

HQL Bug and nullable fields.

Why does this query NOT work FROM WorkflowConfiguration WHERE ((saReplacement IS NOT NULL) AND (:currentTime >= saReplacement.start) AND (saReplacement.end >= :currentTime)) OR ((hrmsAdminReplacement IS NOT NULL) AND (:currentTime >= hrmsAdminReplacement.start) AND (hrmsAdminReplacement.end >= :currentTime)) OR ...

Converting from SQL to HQL fail

Trying to go from here this SQL: SELECT DISTINCT iss.ID FROM Issue AS iss INNER JOIN Message ON Message.IssueID = iss.ID INNER JOIN Clinician ON Clinician.UserID = Message.FromUserID INNER JOIN OrgUnit ON OrgUnit.ID = Clinician.OrgUnitID WHERE OrgUnit.ID = [id-number] To here in HQL: select distinc...

Joining two tables over a compound index in Hibernate

I have Entity A - type - uniqueKey and Entity B - uniqueKey and i dont know how to integrate it into hibernate that i can produce results like from this query: select * from A left join B on B.uniqueKey = A.uniqueKey and A.tpye = 1 where A.id is null this will produce a result that has all the entries of B that are not in A fo...

Does anyone know how to translate LINQ Expression to NHibernate HQL statement?

Dear ladies and sirs. Does anyone know of an existing solution to translate a LINQ Expression to HQL statement? Thanks in advance to all the good samaritans out there. P.S. We already use Linq to NHibernate. However, it only works for select statements, whereas HQL is good for other statement kinds, like delete. So, Linq to NHibernat...

HQL 1 to many count() question

I'm trying to write a query in HQL, and I'm having some trouble with it. It's probably not too difficult, but I'm pretty awful at query languages in general and HQL in specific. Basically, there are three tables, Owners, Pets, and Toys, whose classes look like this: public class Owner { long ownerId; List<Pet> pets; } public class P...

Count function in HQL causing null results?

I have the following HQL query that is attempting to return 2 object instances as well as an aggregate count based upon a 3rd object instance. SELECT client, clientCampaign, count( formData ) FROM FormData as formData JOIN formData.deliveryResults as deliveryResults JOIN formData.leadForm as leadForm JOIN leadForm.campaignForms a...

[HQL/Hibernate] Error: Cannot convert value '0000-00-00 00:00:00' from column 13 to TIMESTAMP

the field definition /** Date. */ @Column(columnDefinition = "datetime") private Date date; setter public void setDate(final Date date) { DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { this.date = dfmt.parse(dfmt.format(date)); } catch (ParseException e) { // TODO Auto-generated catc...

Hql problem in where clause

I have a persistent class Author with two fields: int id, String name. Problem is that whenever I execute query this way: Session s = HibernateUtil.getSessionFactory().getCurrentSession(); s.beginTransaction(); Query q = s.createQuery("from Author"); return (Author)q.list().get(0); It works fine and returns me an Author object with ...

HQL query, how to?

Hi, I am working query with little idea of what software I am dealing with and minimum knowledge HQL. What I am looking is, SELECT Entity1 FROM Entity AS Entity1 WHERE (EXISTS ELEMENTS(Entity1.config.dateTimeInfo.ntpConfig.server) ) But I want to set a condition saying WHERE count(ELEMENTS(Entity1.config.dateTimeInfo.ntpConfig.se...

NHibernate query for object with child collection property

Hi, I need help with an nhibernate query. I would prefer to use Criteria API if possible, otherwise HQL is ok. I have an Employee object with an Account object property, the Account has a collection of Entry objects, and each Entry has an Amount property. (see class diagram). http://www.threeboxes.com.au/employeeQuery1.jpg I need a q...

What is the HQL equivalent of this SQL

Trying to do a bit more complex query, and thought that HQL would be better for the job. Using nHibernate. SELECT * FROM [Group] g INNER JOIN [User2Group] ug on g.Id = ug.GroupId INNER JOIN [User] u ON u.Id = ug.UserId INNER JOIN Activity a on g.ActivityId = a.Id WHERE u.Id = ? AND a.Lineage LIKE '?%' I guess I could also just...

What is the HQL equivalent of this SQL?

SELECT * FROM [Group] g INNER JOIN User2Group ug **on g.Id != ug.GroupId** INNER JOIN [Activity] a on a.Id = g.ActivityId WHERE g.UserId != 2 AND a.Lineage like '0,1,%' Group > 1-n > User2Group < n-1 < User m-n relationship Activity > 1-n > Group 1-n Trying to get all groups that a user has not already added to their account....

Map entity using query in Hibernate

consider table sales (id, seller_id, amount, date) and here is a view that is generated from sales using query SELECT seller_id, SUM(amount) FROM sales GROUP BY seller_id total_sales (seller_id, amount) I want to make an entity for total sales but without the view on the sql side. This entity will be constructed from a query. The ...

GORM Hibernate query

Hi, I have the following Grails domain objects class ProductType { String name static hasMany = [attributes: Attribute] } class Attribute { Boolean mandatory = false Integer seq static belongsTo = [productType: ProductType] } I would like to get all ProductTypes and their mandatory Attributes. Furthermore, I'd ...

Hibernate HQL: Converting a SQL Statement to HQL (with subselects/joins)

Hello Hibernate Experts, i would very much appreciate your help in transforming the following SQL statement to a valid HQL Statement. I tried for hours but was not successfull: SELECT * FROM master as m left outer join (select * from child as c where c.id = (select max(d.id) from child as d where d.MasterFk = c.MasterFk) )as b ON m.id...