java - Hibernate nested queries -


we trying create hibernate specific query below lsession.createquery(lquerystring.tostring()); ............

insert employee_history (emp_status,                               createdby,                               releasedate,                               year)    select case n.emp_status when 0 'draft' else 'final' end,           m.createdby,           m.releasedate,           m.year      employee m, (select count (1) employee_history   b,employee a.emplid=b.emplid , a.year=b.year , b.year=2012 , a.doc_id='xyz') n       a.doc_id='xyz'  getting following exception,i guess because of below statement in query (select count (1) employee_history   b,employee a.emplid=b.emplid , a.year=b.year , b.year=2012 , a.doc_id='xyz') n   org.hibernate.hql.ast.querysyntaxexception: unexpected token: ( near line 1, column 374  insert employee_history (emp_status,                               createdby,                               releasedate,                               year)    select case n.emp_status when 0 'draft' else 'final' end,           m.createdby,           m.releasedate,           m.year      employee m, (select count (1) employee_history   b,employee a.emplid=b.emplid , a.year=b.year , b.year=2012 , a.doc_id='xyz') n       a.doc_id='xyz' 

the exception

at org.hibernate.hql.ast.querysyntaxexception.convert(querysyntaxexception.java:54)     @ org.hibernate.hql.ast.querysyntaxexception.convert(querysyntaxexception.java:47)     @ org.hibernate.hql.ast.errorcounter.throwqueryexception(errorcounter.java:82)     @ org.hibernate.hql.ast.querytranslatorimpl.parse(querytranslatorimpl.java:284)     @ org.hibernate.hql.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:182)     @ org.hibernate.hql.ast.querytranslatorimpl.compile(querytranslatorimpl.java:136)     @ org.hibernate.engine.query.hqlqueryplan.<init>(hqlqueryplan.java:101)     @ org.hibernate.engine.query.hqlqueryplan.<init>(hqlqueryplan.java:80)     @ org.hibernate.engine.query.queryplancache.gethqlqueryplan(queryplancache.java:124)     @ org.hibernate.impl.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:156)     @ org.hibernate.impl.abstractsessionimpl.createquery(abstractsessionimpl.java:135)     @ org.hibernate.impl.sessionimpl.createquery(sessionimpl.java:1770) 

please provide if suggestion/inputs.

it looks, pass sql instead of hql session.createquery(...) method.

see: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html#objectstate-querying-executing

for example in:

insert employee_history (...) 

'employee_history' should entity class name (like employeehistory) not table name.

also in hql can use references defined in entities go through associations avoiding implicit joining ids, here

where a.emplid=b.emplid , ... 

consider example url above:

select mother cat cat join cat.mother mother cat.name = ? 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -