日期:2014-05-20 浏览次数:20846 次
public List getCity() { //方法 // TODO Auto-generated method stub session = HibernateSessionFactory.getSession(); List list = session.createQuery("select new com.snzo.dao.WorldOnlinePortCity(wp.id,wp.name) from WorldOnlinePortCity as wp").list(); //用过直接 new WorldOnlinePortCity(wp.id,wp.name) session.close(); return list ; } public static void main(String []args){ 测试 List list = new City_Imp().getCity(); for(Iterator it = list.iterator();it.hasNext();){ WorldOnlinePortCity goods = (WorldOnlinePortCity)it.next(); System.out.println(goods.getId()); } } public class WorldOnlinePortCity implements java.io.Serializable { //持久化类 // Fields private Long id; private String name; private String des; private Set city; // Constructors /** default constructor */ public WorldOnlinePortCity() { //默认构造 } /** minimal constructor */ // public WorldOnlinePortCity(Long id) { // this.id = id; // } /** full constructor */ public WorldOnlinePortCity(Long id, String name, String des,Set city) { //构造函数 this.id = id; this.name = name; this.des = des; this.city=city; //Set 类型 不写也试验过 报一样的错。 } 不管 怎么写 都这这样的错误 错误: Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.snzo.dao.WorldOnlinePortCity] [select new com.snzo.dao.WorldOnlinePortCity(wp.id,wp.name) from com.snzo.dao.WorldOnlinePortCity as wp] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583) at com.snzo.bo.City_Imp.getCity(City_Imp.java:75) at com.snzo.bo.City_Imp.main(City_Imp.java:81) Caused by: Unable to locate appropriate constructor on class [com.snzo.dao.WorldOnlinePortCity] [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.snzo.dao.WorldOnlinePortCity] at org.hibernate.hql.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:122) at org.hibernate.hql.ast.tree.ConstructorNode.prepare(ConstructorNode.java:88) at org.hibernate.hql.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:837) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1952) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1821) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1392) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218) ... 10 more // 在线查了很多资料 依然没有找到原因 在线等 高手 解答 谢谢.