彭老师,sample_hibernate出错!贴出了日志

oojdon 07-10-17

banq老师,我使用tomcat+mysql运行sample_hibernate成功,于是想测试一下模型修改,我在模型中增加了一个String字段,同时也修改了相应的边界模型,然后改了user.jsp中的表单和usrList.jsp的相应部分,删除temp和work目录下的所有临时文件以及usertest数据表,编译成功然后运行时程序不能自动创建数据表,插入数据出错。下面是日志,请帮我分析分析,谢谢!!
2007-10-16 23:11:42,656 [http-80-2] ERROR com.jdon.persistence.hibernate.HibernateTemplate - exception while execute
org.hibernate.hql.ast.QuerySyntaxException: UserTest is not mapped [select count(user) from UserTest user ]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
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:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
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(QueryPlanCache.java:72)
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:1623)
at com.jdon.persistence.hibernate.HibernateTemplate$29.execute(HibernateTemplate.java:452)
at com.jdon.persistence.hibernate.HibernateTemplate.doHibernate(HibernateTemplate.java:74)
at com.jdon.persistence.hibernate.HibernateTemplate.find(HibernateTemplate.java:450)
at com.jdon.persistence.hibernate.HibernateTemplate.find(HibernateTemplate.java:442)
at com.jdon.framework.test.dao.JdbcDAO.getModels(JdbcDAO.java:48)
at com.jdon.framework.test.service.TestServicePOJOImp.getAllUsers(TestServicePOJOImp.java:100)

banq
2007-10-17 08:40

主要是运行时程序不能自动创建数据表,这是hibernate.cfg.xml中 <property name="hbm2ddl.auto">update</property>
重新编译部署后,再查看数据库,应该制动创建,否则就是在数据库配置链接等参数方面问题,与程序无关,这些都是系统配置性质方面,需要细心就可以。

oojdon
2007-10-17 13:27

hibernate.cfg.xml的配置和sample_hibernate的配置完全相同,<property name="hbm2ddl.auto">update</property>我也根本就没动它,既然sample_hibernate可以正常运行,证明数据库配置是正确的,我真的是找不出原因!!

oojdon
2007-10-17 15:14

banq老师,问题已经解决,原因是我把模型中的
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
删除了,这些类是用在EJB中,怎么会影响tomcat的测试?

oojdon
2007-10-17 15:19

sample_jdbc始终运行不成功,我的数据库连接池在jsp+javabean的系统中是没有问题的,同样的java:comp/env/jdbc/TestDB配置在jdonframework中怎么就不行呢?

3Go 1 2 3 下一页