hql

Why does HQL suppress results if using properties on null in or-clause

I just discovered a strange problem when dealing with HQL queries on nested objects. My class looks like this: class MyClass { MyClass predecessor } So using predecessor, I can build a Hierarchy. Now let's say I have a "thin" tree like this: obj1.predecessor = null obj2.predecessor = obj1 obj3.predecessor = obj2 obj4.predecessor =...

Hibernate Exception

org.hibernate.hql.ast.QuerySyntaxException: cannot dereference scalar collection element: cspName st.append("SELECT customers.name,sum(csp.cspValue) as TotalMoney "); st.append("from Account as account "); st.append("left join account.CSPFields as csp with ((account.accountID=csp.id) and (csp.cspName = 'Target')...

GORM Querying where filter is not a direct attribute of a class.

I am trying to figure out the most efficient / effective way of performing a certain type of query using Grails GORM. This is the scenario where I want to query all of the children / linked items in a many to one relationship. This is a one way relationship whereby the many side used the id of the thing it is linked to. One example in...

Hibernate Execption

i want to try to find out all the fieldValue based on fieldName MNC.java: `private Map <String, String>formFields = new HashMap<String, String>(); public void setFieldValue(String fieldName, String fieldValue) { if (formFields == null) { formFields = new HashMap<String, String>(); } formFields.put(f...

Hibernate Query to fetch records on date ignoring timestamp

I have a timestamp column tradedate in one of the DB(Oracle) tables. I am using hibernate as the persistence layer to fetch and store Data to DB. I have a requirement in which I need to query the DB on date. i.e From UI the user passes a date and I need to get the filtered data based on this date. If the tradedate column only has the d...

hibernate question

if i use table name instead of class name in HQL query like this: select classname.field name as obj from table name and i have specified mapping in hbm file. but it show exception: table name is not mapped and second thing is i have use on keyword in query then it show exception: unexpected token: on ...

New object with HQL

Trying to create an object from an HQL query, but just can't figure out what i'm doing wrong. Query: String query = "SELECT product.code, SUM(product.price), COUNT(product.code) from Product AS product GROUP BY product.code" (or should I use new MyCustomList(product.code, SUM(... , even though it's not mapped?) Now I want to cast thi...

Reading an entire database with Nhibernate

Hi, If I use HQL I am able to query the entire system with this: session.CreateQuery("from System.Object") But then I just get all objects in a list, are there any way similar to this to also get all collections populated? ...

Can you perform complex aggregate operations using NH3?

I need to perform a grouping aggregation similar to something like this in T-SQL: select b.Name as [Grouped Name], COUNT(distinct a.ID) as [Grouped Count], COUNT(distinct c1.ID) as [Second Group Count], COUNT(distinct c2.ID) as [Third Group Count] from TableA a left join TableB b on a.ID = b.TableAID left join TableC c1 on a.ID = c1.T...

JPQL/HQL count(collection) in where clause

hey everybody, I'm struggling to find the solution for the following problem: I want to get all the picture albums which have at least one picture. In SQL i would to something like: SELECT pa.id FROM album pa JOIN picture pi ON pa.id = pi.album_id GROUP BY pa.id HAVING count(pi.id) > 0 But I don't know how to do this in JPQL... Obv...

how to filter result from many to many using nhibernate hql

I have many to many relation between Posts and Tags tables. Using HQL I want to get only a few fields from Posts table and names of the tags. So I wrote: select p.field1, p.field2, count(distinct p.field3), t.Name from Post p left join p.Tags t group by p.field1, p.field2, t.Name I want to have post data and list of its tags. Result ...

JPA QL - "winning bids of a user"

Hi, I have a simple app with User, Bid, and Auction, the relationships are clear I hope. Now I want to implement getWinningAuctionsOfuser( User u ), which would return the auctions which the given user is currently winning. I know how I would do this in SQL, but I don't have much experience with JP-QL. What's the best approach? Curr...