-->
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: Native SQL resulting in parser exception for inner query
PostPosted: Mon Sep 19, 2011 9:43 am 
Newbie

Joined: Mon Sep 19, 2011 9:37 am
Posts: 3
The following piece of code results in

Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 209


Snippet.

Code:
   
private static String orgMatrix =
   "SELECT  usr.id as userId, usr.name, usr.alias, usr.phone, rmap.name as role, pmap.value as pincode, caller.customer_per_cycle as customersPerCycle, org.reportee_id as reportee FROM t_user usr " +
   /* The nested joins are required for multi-valued properties */
    "LEFT OUTER JOIN (SELECT t1.user_id, t2.name from t_user_role t1 INNER JOIN t_role t2 ON t1.role_id = t2.id) rmap ON usr.id = rmap.user_id " +
    "LEFT OUTER JOIN (SELECT t1.user_id, t2.value from t_pincode_map t1 INNER JOIN t_pincode t2 ON t1.pincode_id = t2.id) pmap ON usr.id = pmap.user_id " +
    /* For single valued properties */
    "LEFT OUTER JOIN t_caller caller ON usr.id = caller.id " +
    "LEFT OUTER JOIN t_seller seller ON usr.id = seller.id " +
    /* Return the entire organization matrix under the given user */
    "LEFT OUTER JOIN t_org org ON usr.id = org.user_id " +
    "START WITH org.user_id = ? CONNECT BY PRIOR org.reportee_id = org.user_id";

     Session session = ....;
    Query query = session.createQuery(orgMatrix).setInteger(0,3).setResultTransformer(Transformers.aliasToBean(OrgMatrix.class));


The inner SQL conditions starting with "(" results in failure. Is there any way to escape those ?


Top
 Profile  
 
 Post subject: Re: Native SQL resulting in parser exception for inner query
PostPosted: Mon Sep 19, 2011 4:34 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Session.createQuery() is used for HQL (Hibernate Query Language) queries. If your query is a native SQL query you should use Session.createSQLQuery() instead.


Top
 Profile  
 
 Post subject: Re: Native SQL resulting in parser exception for inner query
PostPosted: Tue Sep 20, 2011 1:17 am 
Newbie

Joined: Mon Sep 19, 2011 9:37 am
Posts: 3
I made a bad mistake. Typical example of being overworked.

Why on earth would hibernate try to parse a native SQL !!


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.