When I try to get the composite key for a table using a simple query. I get the following error
1) testGetTemplate(TestGroupUser)org.hibernate.QueryException: path expression ends in a composite value: template0_.id [from com.narval.util.dbutil.dao.Templat
e d where d.id= ? ]
at org.hibernate.hql.classic.PathExpressionParser.getWhereColumn(PathExp
ressionParser.java:389)
at org.hibernate.hql.classic.WhereParser.doPathExpression(WhereParser.ja
va:363)
at org.hibernate.hql.classic.WhereParser.doToken(WhereParser.java:382)
at org.hibernate.hql.classic.WhereParser.token(WhereParser.java:263)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingPars
er.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslator
Impl.java:192)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslator
Impl.java:168)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCa
che.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessio
nImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImp
l.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at TestGroupUser.testGetTemplate(TestGroupUser.java:466)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at TestGroupUser.main(TestGroupUser.java:90)
FAILURES!!!
My Hibernate version: 3.0.1
My code
TemplateCompositeKey tempKeyID = new TemplateCompositeKey("a","b");
Template tempID = new Template(tempKeyID );
Session session = HibernateUtil.getSession();
Query q = session .createQuery("from Template d where d.id= ? ");
q.setParameter(1, tempID);
templ = (Template) q.list().get(0);
System.out.println("template Name is "+templ.getName());
session.close();
My hbm mapping
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 19, 2006 3:45:43 PM by Hibernate Tools 3.2.0.beta6a -->
<hibernate-mapping>
<class name="com.narval.util.dbutil.dao.Template" table="T_TEMPLATE_NRVL" schema="BHFM">
<composite-id name="id" class="com.narval.util.dbutil.dao.CompositeTemplate">
<key-property name="templateId" type="string">
<column name="TEMPLATE_ID" length="10" />
</key-property>
<key-property name="templateVer" type="string">
<column name="TEMPLATE_VER" length="10" />
</key-property>
</composite-id>
<property name="name" type="string">
<column name="NAME" length="200" />
</property>
</class>
</hibernate-mapping>
|