java - org.hibernate.QueryException: could not resolve property: company of: Party [from Party party where party.company.name = :companyName] -
i have following class:
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "party", proporder = { "company" }) @entity(name = "party") @table(name = "party") @inheritance(strategy = inheritancetype.joined) public class party implements equals, hashcode, tostring { @xmlelement(name = "company") protected companytype company; /** * gets value of company property. * * @return * possible object * {@link companytype } * */ @manytoone(targetentity = companytype.class, cascade = {cascadetype.all}) @joincolumn(name = "company_0") public companytype getcompany() { return company; } /** * sets value of company property. * * @param value * allowed object * {@link companytype } * */ public void setcompany(companytype value) { this.company = value; } }
this companytype class:
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "companytype", proporder = {"name"}) @entity(name = "companytype") @table(name = "companytype") @inheritance(strategy = inheritancetype.joined) public class companytype implements equals, hashcode, tostring { @xmljavatypeadapter(stringtrimadapter.class) protected string name; /** * gets value of name property. * * @return * possible object * {@link string } * */ @basic @column(name = "name", columndefinition = "text") public string getname() { return name; } /** * sets value of name property. * * @param value * allowed object * {@link string } * */ public void setname(string value) { this.name = value; } }
i used following query fetch data:
query q = null; q = session.createquery( "from party party party.company.name = :companyname") .setparameter("companyname", companyname); return classutils.cast(q.setresulttransformer(distinctrootentityresulttransformer.instance).list());
but, got following error:
org.hibernate.queryexception: not resolve property: company of: party [from party party party.company.name = :companyname] @ org.hibernate.queryexception.generatequeryexception(queryexception.java:137) @ org.hibernate.queryexception.wrapwithquerystring(queryexception.java:120) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:234) @ org.hibernate.hql.internal.ast.querytranslatorimpl.compile(querytranslatorimpl.java:158) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:126) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:88) @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:190) @ org.hibernate.internal.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:301) @ org.hibernate.internal.abstractsessionimpl.createquery(abstractsessionimpl.java:236) @ org.hibernate.internal.sessionimpl.createquery(sessionimpl.java:1800) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.hibernate.context.internal.threadlocalsessioncontext$transactionprotectionwrapper.invoke(threadlocalsessioncontext.java:356) @ com.sun.proxy.$proxy104.createquery(unknown source)
any appreciated. thank you.
i believe missing join
in hql query;
q = session.createquery( "from party party inner join party.company company company.name = :companyname") .setparameter("companyname", companyname);
Comments
Post a Comment