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 ?