-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Why do I search and can't use nickname in the hibernate?
PostPosted: Wed Aug 30, 2006 10:35 pm 
Newbie

Joined: Wed Aug 30, 2006 9:06 pm
Posts: 1
session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from Who where name='aa'");
这样才行



session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from Who a where a.name='aa'");
要是这样就出错
org.hibernate.QueryException: could not resolve property: name of: Who [ from Who a where a.name='aa']
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
at org.hibernate.hql.ast.FromElementType.getPropertyType(FromElementType.java:273)
at org.hibernate.hql.ast.FromElement.getPropertyType(FromElement.java:349)
at org.hibernate.hql.ast.DotNode.getDataType(DotNode.java:474)
at org.hibernate.hql.ast.DotNode.prepareLhs(DotNode.java:208)
at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:166)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:463)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:863)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3190)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at DAOFactory.query(DAOFactory.java:26)
at DAOFactory.main(DAOFactory.java:47)
Exception in thread "main"

是不是我配置出错啊,我是用myeclipse自动生成的
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="Who" table="who" schema="dbo" catalog="spdb">
<composite-id name="id" class="WhoId">
<key-property name="name" type="string">
<column name="name" length="50" />
</key-property>
<key-property name="password" type="string">
<column name="password" length="50" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 3:17 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
Hi cnmyth,

the property "name" is part of your composite id, therefore you have to qualify it using "id":

Code:
session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from Who where id.name='aa'");


or:
Code:
session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from Who a where a.id.name='aa'");


Regards,
Georg

P.S.: Please rate this posting if it helps you solving the problem

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.