SSH框架开发异常记录:nested exception is org.hibernate.hql.ast.QuerySyntaxException

来源:互联网 发布:java读取log日志文件 编辑:程序博客网 时间:2024/06/06 09:53
org.springframework.orm.hibernate3.HibernateQueryException: AdminUser is not mapped [from AdminUser where username = ? and password = ?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: AdminUser is not mapped [from AdminUser where username = ? and password = ?]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:656)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)

at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)

关键错误信息在上面的Hibernate无法映射AdminUser这个实体这句话。

那么有哪些情况会造成这个错误呢?

首先我梳理一下hibernate工作原理,把实体类映射到数据库中的表,需要以下几点:

1、实体类

2、映射文件

3、如果是搭配spring,而配置文件又是交由spring容器管理的话,那么也需要在applicationContext.xml中配置

然后开始排查错误,首先看实体类与映射文件是否一致,表名,字段类型等,没有问题,之后看数据库中表结构与映射文件是否匹配,如id增长类型,发现也没问题;

那么就应该是spring的配置文件了,果然是忘了在里面将映射文件交给spring管理。

问题解决

2 0
原创粉丝点击