询问一个hibernateTemplate的简单问题
本帖最后由 danbomingli_88 于 2014-01-23 16:22:11 编辑 我的HQL语句是这样的
select username2,realname from Friends f,Users u where f.username1=? and f.username2=u.username order by u.username asc", username1
但我这样用是错误的:(本身的语句没有问题,我转为sql语句,在sql server中运行正确)
List<String[]> list = null;
list = hibernateTemplate.find("select username2,realname from Friends f,Users u where f.username1=? and f.username2=u.username order by u.username asc", username1);
问题应该就在于hibernateTemplate.find的返回值类型了。
应该是什么呢?怎么写?
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
No data type for node: org.hibernate.hql.ast.tree.IdentNode +-[IDENT] IdentNode: 'username2' {originalText=username2}
File:org/hibernate/hql/ast/tree/SelectClause.java
Line number:156
Stacktraces
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode +-[IDENT] IdentNode: 'username2' {originalText=username2}
org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:156)
org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:852)
org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:640)
org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:685)
org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101)
org.hibernate.engine.query.HQLQueryPlan.(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)
org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:914)
org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:908)
……………………略
[解决办法]