java - JPA typed Query passing values in a Map in constructor -
in jpql typedquery
can select values , directly pass values in other class's construtor. working fine. want selected record in key value paired map can pass whole map in variable argument construtor , assign values class property name map (by getting values property name). there way achieve this?
here query:
hqlquery.append("select new mypackage.myclass( new map('employeecode',he.employeecode) , new map('resignationid',he.employeeid))"); myclass{ private string employeecode; private integer employeeid; public myclass(map<string, object>... maps) //variable map { super(); (map<string, object> map : maps) { if (map.containskey("employeeid")) { this.employeeid= (integer) map.get("employeeid"); } if (map.containskey("employeecode")) { this.employeecode = (string) map.get("employeecode"); } } }
i want dont have remember construtor argument order in case when there many attribute of class.
when creating query getting error:
caused by: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected token: new near line 1, column 70 [select new com.talentpact.businessobject.resignation.resignationto( new map('resignationid',resignation.resignationid) ) com.talentpact.model.hremployeeresignation resignation join resignation.hremployee left join resignation.expectedrelievingdateid resignation.resignationid=:resignationid ] @ org.hibernate.hql.internal.ast.querysyntaxexception.convert(querysyntaxexception.java:54) @ org.hibernate.hql.internal.ast.querysyntaxexception.convert(querysyntaxexception.java:47) @ org.hibernate.hql.internal.ast.errorcounter.throwqueryexception(errorcounter.java:79) @ org.hibernate.hql.internal.ast.querytranslatorimpl.parse(querytranslatorimpl.java:276) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:180) @ org.hibernate.hql.internal.ast.querytranslatorimpl.compile(querytranslatorimpl.java:136) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:101) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:80) @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:119) @ org.hibernate.internal.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:214) @ org.hibernate.internal.abstractsessionimpl.createquery(abstractsessionimpl.java:192) @ org.hibernate.internal.sessionimpl.createquery(sessionimpl.java:1537) @ org.hibernate.ejb.abstractentitymanagerimpl.createquery(abstractentitymanagerimpl.java:295) ... 165 more
Comments
Post a Comment