hql

How to convert this HQL query with QueryOver?

Hello all, I have the following HQL query: return Session.CreateQuery("from Player p where p.Sex = :teamSex and p.Visible and not exists (from PlayerInTeam pit where pit.Player = p and pit.Roster.Team = :teamId)") .SetParameter("teamId", team.Id) .SetParameter("teamSex", team.Sex) .Enumerable<Player>(); How would you writ...

How to use the CURRENT_DATE function in a hibernate criterion?

I want to translate the following HQL into Criteria notation: from Deal where CURRENT_DATE between startDate and endDate I tried using Restrictions.between but it doesn't recognize current_date Criteria c = session().createCriteria(Deal.class) .add(Restrictions.between("CURRENT_DATE", "startDate", "endDate"); ...

convert HQL query to criteria api

I'm wondering if is possible to convert this HQL query into a criteria api query. select s1 from Student where ( select max(s2.Score) from Student where s1.Id = s2.Id ) = 10 (selects the students that have their max score value equal to 10) I don't know if I could use a detached criteria beca...

Grails: Updating a single object in a domain, ".save" Vs ".executeUpdate"

I'm wondering what the most efficient way of updating a single value in a domain class from a row in the database. Lets say the domain class has 20+ fields def itemId = 1 def item = Item.get(itemId) itemId.itemUsage += 1 Item.executeUpdate("update Item set itemUsage=(:itemUsage) where id =(:itemId)", [usageCount: itemI...

Why does this HQL delete fail, when an HQL select with same terms works?

Why does the following HQL query fail? string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) ...

HQL restriction on child collection

I have a class which has a collection public class Parent { ... ISet<Child> Children; ... } Given a list of child names, I'd like to return parents whose Children property contains all items of this list. I managed to write an HQL query, but it works for a single name, not a whole list : SELECT p FROM Parent AS p JOIN p....

Pass a parameter to select case with group by in HQL

I have the following HQL(The Hibernate Query Language) query (which is executed on oracle db connection) to retrieve an aggregated sum, based on month select sum(doc._masskg), case when (month(doc._date) = month(:m)) then 'NOW' else 'BEFORE' from Document doc where month(doc._date) <= month(:m) group by case when (mont...

NHibernate HQL - select count(*) with having - can't get it to work

Trying to run the following HQL with NHibernate: select count(distinct t) as TweetCount from Tweet t join t.Tweeter u left join t.Votes v left join t.Tags tag where t.App = :app having count(distinct v) > 0 But for some reason the having clause is being ignored and it's counting all tweets when only 2 tweets have a vote. I...

HQL query: how to use "is empty" expression?

I am a beginner in NHibernate queries. And an easy task enters me into a stupor. Trying to get list of hotels filtering by cityIDs (where the hotels are located in) or all hotels if list of CityiIDs is empty. So, writing: var q = CurrentSession.CreateQuery(@"from Hotel h where :cityIds is empty or h.City.ID in (:cityIds)"). SetParamete...

Hibernate query where item in list

Can anyone suggest the correct syntax for a where clause using in applied to a list? The following query in an .hbm file generates a parse exception: <query name="Nutrient.findNutrients1"> <![CDATA[from Nutrient as nutrient where nutrient.id in elements(?)]]> </query> The exception follows: PARSER.reportError(56) | line 2:95: ...

hql join - Path expected for join

I have the following hql. This works fine if i don't try and include the "OrderItem" entity. I understand that there is no "on" clause in hql. What is the best way to join orderItem var hql = new StringBuilder(); hql.Append( @"select p.Id, p.Name, p.Description, p.ProductKey, p.CustomerSku, p.ImageUrl, p.ImageThumbUrl, p.Ima...

hibernate not mapping the bean, returning Object List

hi am new and hibernate is driving me crazy full time. i hv 2 tables one-2-one mapping. when i join only these 2 these two then hibernate is not mapping and when i join table1 with some other table3 then its giving me fine mapped results. Bean1 private int id ; private BlessUser blessUser ; private SnsAuthenticator snsAuth ; public vo...

Hibernate - different behavior on Linux and Windows

I've run into a peculiar problem where a hql query is working as expected on Windows but does not on Linux. Here is the query: select distinct resource from Resource resource , ResourceOrganization ro where (resource.active=true) and (resource.published=true) and ((resource.resourcePublic=true) or ((ro.resource.id=resource.id and r...

Hibernate Left Outer Join problem: path expected on join

I have two tables, something like: Article and ArticleRelevance They have a one to one relationship, and ArticleRelevance is optional, meaning a Article may (or may not) have a ArticleRelevance. I want to select all articles along with the ArticleRelevance details. With traditional SQL, I will do a outer join on the tables, like SEL...

Why does using a column name directly in HQL only work sometimes?

I have two HQL queries I am using for a quick-and-dirty unit test. The first looks somewhat like this: from Foo where SOME_FOREIGN_KEY = 42 The second looks like this: from Foo as foo inner join foo.Bar as bar where foo.SOME_FOREIGN_KEY = 42 The SOME_FOREIGN_KEY column is not the name of something that Hibernate knows is mapped. ...

How do I select the nth element in a Collection by the number in an @IndexColumn?

I have an ItemEntity class, which has a collection of ImageEntity's. I want to be able to fetch a specific ImageEntity, given its index in the collection. For example, for an ItemEntity with 10 ImageEntity's, I want the 4th ImageEntity in as few database hits as possible. I've read Hibernate In Action and googled, but every piece of d...

How to change to case of a column to Upper in HQL Hibernate

Hi I want to change a column from a table to uppercase before using like and filtering what is the keyword in HQL? here's my query SELECT abc FROM ABC abc WHERE abc.id = ? And upper(abc.description) like '%?%' Thanks ...

NPE in HQL subquery

I have an error in the following HQL Query: em.createQuery( "SELECT new com.magenta.sovereign.entity.view.ThirdPartyReportView(" + "e.id, " + "e.vehicleRegistrationNumber, " + "e.driverName, " + "e.thirdPartyAssignee.firstName, " + ...

Different results fetching results with query api vs. hql

I have the following entity (not exact but gives a general idea): @Entity public class WebElement implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) private Set<CoreElement> coreElements; ...

NHibernate Delete with date arithmatic using HQL

Hello, I've looked around and can't find too much. But is it possible to do something like this using HQL in nHibernate: Session.CreateQuery(@"DELETE FROM MyObject mo WHERE (mo.AlteredDate + mo.ExpiryDetails.ExpiryTimestamp) < :pNow") .SetDateTime("pNow", DateTime.Now); So basically I want to...