hql

HQL - find entity where property x is highest

Can HQL queries do this? "get the UserEntity where the property creationTimestamp is the most recent of all UserEntities". Essentially a query to return the "newest user" in our program where each UserEntity has a field mapped to a timestamp column in our database. ...

Hibernate Session closed problem!

The function below is the actionListener for a button I have in my web application, I am deleting the old chosen rows from a table in a database and inserting the new ones to the database. public void getSelectedExemptionItems(ActionEvent ae) { Session hibernateSession; Session hibernate2Session; selectedExemptio...

NHibernate SQLquery for paging to HQL / ICriteria

Hello everyone! I'm making a query that sorts and returns X rows based on row_number() I'm using NHibernate with MSSQL and im trying to get paging working using CreateSQLQuery and i have this query: select s.* from( select distinct release.[stop], survey.SurveyId, survey.Created, survey.CopyOfId, survey.DesignTemplateId, survey.Us...

Hibernate criteria distinct with join - fetch the relation

Hello, I've searched on the internet but I didn't understand very much the problem: I'm trying to build a distinct query using criteria and a distinct clause using a projection, trying to resole the lazy attribute of the projection in the distinct. So the query will be like this Code: createCriteria(Parent.class) .setProject(Pro...

Nhibernate Hql query retrieve DateTime empty

Hi I need hql query for retrieving objects with an empty value in a datetime property Something like that from Users u where u.LastLogon is empty LastLogon is a DateTime? property, datetime in the MS Sql Table How can you do that? ...

Help with HQL Joins

I have the following SQL which I can't work out how to convert to HQL.... SELECT dbo.Style.Id, dbo.Style.Name FROM dbo.Price JOIN dbo.PriceGroup ON dbo.Price.priceGroupId = dbo.PriceGroup.Id JOIN dbo.Product ON dbo.Price.productId = dbo.Product.Id JOIN dbo.Style ON dbo.PriceGroup.Id = dbo.Style.priceGroupId WHERE (dbo.Produc...

Object query language | execute both "order by" and "where" clauses

How do I sort out some data according to an where clause and a order by clause using object query language this is the query that I'm using but i'm not sure if it is working or not. SELECT user from user.User as user WHERE user.status=1 order by user.username Thanks. ...

Is there a HQL equivalent to datediff for NHibernate?

I haven't found a clear answer but I would like to grab any values from within the past 24 hours. I have an alternative solution in code but I would like to see if there is an equivalent to using t-sql datediff ...

How do i transform a HQL result to List<T> where T is a mapped class.

I have this nhibernate query: var q = NHibernateSession.Current.CreateSQLQuery ( @"SELECT LastestEvents.* FROM ( SELECT DISTINCT SbQcontainer.Container FROM HistoricEvents SbQc...

Hibernate HQL Query : How to properly use ANY function in where clause?

I'm struggling to understand my error in an HQL query: public List<Pats> getIds(List<String> patIds) { Session session = getSession(); String hql = "from OurPats where patId = any (:patIds)"; // String hql = "from OurPats where patId in (:patIds)"; return session.createQuery(hql).setParameterList("patIds", patIds).list()...

NHibernate how to join to table twice in HQL

public class Case { public int Id { get; set; } public string Number { get; set; } public Employee Employee { get; set; } } public class Employee { public int Id { get; set; } public string EmployerIdentifier { get; set; } public Case Case { get; set; } } There is a one to one releationship between Case and Emp...

Hibernate HQL update with a subselect in set clause

Hi all, I'm trying to do an update in hibernate HQL with a subselect in a set clause like: update UserObject set code = (select n.code from SomeUserObject n where n.id = 1000) It isnt working, it is not supported? Thanks Udo ...

NHibernate: help translating an hql query to use criteria api instead

I have the following hql query which I'd like to switch over to the criteria API select a.Id as Id, a.Name as Name, a.ActiveStatus as ActiveStatus, dbo.GetActivityStartDate(a.Id) as StartDate, dbo.GetActivityEndDate(a.Id) as EndDate, coalesce(ac.Id,0) As CategoryId, coalesce(ac.Name,'') As CategoryName from Activity as a left oute...

Automatic join with NHibernate / Many-to-one / HQL

Hello everyone, I'm working on a .NET C# project on which I had to use NHibernate Mapping Attributes to map my objects to my tables in my database. Now let's explain what my problem is. I have two mapped classes, for example ClassA and ClassB. In my database, table A contains a foreign key referencing the primary key of table B. Hence...

Hibernate queryCount with a condition

Hello, I'd like to make an hibernate query. My old query was like : public int getPublicationCountVote(Publication pub,Boolean voteType){ return HibernateUtil.queryCount(SocialVote.class , new String [] {VOTED_PUBLICATION_ID_FIELD, FOR_OR_AGAINST_FIELD} , new Object [] { pub.getId() , voteType }); } But now, ...

Hql statement not returning distinct values when specified.

Hello experts! As the title states I have some issues with my hql statement. I have two entities: SecondEntity: public class SecondEntity implements Serializable { @Id @GeneratedValue private Long id; @ManyToOne @JoinColumn(name = "firstEntityId") private FirstEntity firstEntity; @NotNull(message = "the b...

How do I sort a linked list in hql?

Same question as this, only I'd like to do it in Hibernate (using grails if that matters). So the domain class looks like this class LinkedElement { LinkedElement precedingElement String someData } and I'd like to query all elements in their linked order (where the first LinkedElement has null as the precedingElement). Is this po...

Nested Select Using HQL

Hi, I would just like to know if derived queries can be handled by HQL? I have this bit of code right here and it kept on saying that it did not expect the '(' symbol right after the first FROM keyword. Your help will be much appreciated. Thanks. "SELECT new " + Distribution.class.getName() + " (adhoc, deployment, design, development, "...

Can I select null as a column value in HQL query?

I need a list with three columns. column 1st and 3rd having values while 2nd as null. Can I do it through HQL query? I need something like this: select id, null, name from MyClass Where MyClass as well as underlying table has only two properties/columns ie, "id" and "name" ...

Error in my hibernate request

Hello i have this HQL request and i have an error when I run it My function: public ProprietaireInt getProprietaireInt(String codeImmeuble, String annee) { //Create connexion Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); ProprietaireInt proprietaireInt = new ProprietaireInt(); try{ ...