-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Inconsistent tolerance of reserved HQL keywords as aliases
PostPosted: Tue Jan 10, 2006 1:14 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Hibernate version: 1.0.1

While a query such as

Code:
SELECT Order.Date,
       Order.PoNumber,
       OrderStatus.Description
FROM Order AS Order
JOIN LEFT JOIN Order.OrderStatus AS OrderStatus


fails with the (not too surprising) exception

Code:
QueryException: BY expected after GROUP or ORDER: LEFT [FROM MyCompany.Entities.Order AS Order
LEFT JOIN Order.OrderStatus AS OrderStatus]
   at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)
   at NHibernate.Hql.PreprocessingParser.Token(String token, QueryTranslator q)
   at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)
   at NHibernate.Hql.QueryTranslator.Compile()
   at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)
   at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
   at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
   at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
   at NHibernate.Impl.QueryImpl.List()


the simpler query

Code:
SELECT Order.Date,
       Order.PoNumber,
FROM Order AS Order


actually works fine. If reserved HQL keywords like ORDER and GROUP can be used as aliases in the FROM clause, why can't they be used in a JOIN clause?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 11:35 pm 
Beginner
Beginner

Joined: Mon Oct 17, 2005 1:58 am
Posts: 27
I may be wrong but Is OrderStatus a member of Order ?

If so then I think the query should be like
SELECT Order.Date,
Order.PoNumber,
Order.OrderStatus.Description
FROM Order AS Order
LEFT JOIN FETCH Order.OrderStatus AS OrderStatus

You are using 'JOIN LEFT JOIN'.I think You should use 'LEFT JOIN FETCH'


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 12:53 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Sorry, the "JOIN LEFT JOIN" was a typo.

Actually, while your form of the query would work as well, we need the query in the form originally shown (at least until we write a smarter HQL parser), because then we can easily parse the HQL and execute a modified statement to get the underlying entities. As a general policy, we want every query to have entities returned, not raw scalar values.

As long as our queries are in the form

SELECT A.Foo, B.Bar, C.Ack, D.Ugh, ...
FROM Ablah AS A
JOIN x1.y1 AS B
JOIN x2.y2 AS C
JOIN x3.y3 AS D
...

i.e. as long as nothing in the select list or joins goes deeper as in "SELECT A.B.Bar" or "JOIN x1.y1.z1", then we can easily parse the HQL to determine the datatypes of the selected properties, and instead issue the HQL statement without the SELECT clause. The raw query results (an object array of entities A, B, C, D ...) are then packaged into a nice "entity view row" class, where the entities are available as a dictionary keyed by their aliases in the query, and each selected property is exposed with the correct datatype, with property names A_Foo, B_Bar, C_Ack, D_Ugh ... The "entity view row" class is generated by a utility we created similar to NHibernate Query Analyzer, which we will eventually make into a Visual Studio plug-in. For cases where the query is dynamic (i.e. can't be specified at compile-time), we generate, compile and load the "row" class at runtime.

This way, when creating a UI, the developer specifies what properties they want displayed in their UI in the HQL statement, and they get back a nice set of "entity view row" objects with the properties they want to bind to, flattened to one level for easy databinding, and the underlying entities so that the user can do stuff like drill down or invoke some operation on a displayed property's underlying entity.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.