现在的位置: 首页 > 综合 > 正文

org.hibernate.hql.ast.QuerySyntaxException: UserType is not mapped

2013年11月07日 ⁄ 综合 ⁄ 共 2473字 ⁄ 字号 评论关闭

报错代码:
main.java.com.aosa.app.base.exception.ASSystemDaoException: class main.java.com.aosa.orm.hibernate.mysql.impl.BaseDAOImpl-queryHql(String HQL)
       .........
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.orm.hibernate3.HibernateQueryException: UserType is not mapped [FROM UserType]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: UserType is not mapped [FROM UserType]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
.......
... 72 more
Caused by: org.hibernate.hql.ast.QuerySyntaxException: UserType is not mapped [FROM UserType]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
...................
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:914)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)

原因:
在bean.xml中未配置数据库对应的实体类引用路径!

解决办法:
在bean.xml中添加:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>main.java.com.zzz.web.app.test.vo</value>
<value>main.java.com.zzz.app.module.model</value>  <!--在此处增加你对应的数据库实体类路径--!>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
有的是在这儿添加:
<value>badyflf/action/mapping/Product.hbm.xml</value>
自己解决问题的过程:
刚开始发现Spring注解不管用,报错(空指针),检查和不断再次配置,发现没有错啊。最后关掉MyEclipse,发现OK了(有时候用IDE很伤人)。
然后报错的问题就是说UserType is not mapped(UserType是我的一个数据库实体类),开始怀疑是不是配置实体类配置错误了。检查,反复检查,还是没有错。百般无赖之下,google一下。google到许多方法,还是不管用。直到发现一个帖子跟我的类似,我去检查一下配置中的路径,结果解决了
!我的方法和解决我问题的帖子方式不一样,所以也写一个,自己不忘记,朋友们遇到也可以查阅!

--------我是分割线-------------------
小问题,但是发现网络上的朋友遇到的还是许多哦,但是大多数没有回复。so....

转载请说明出处:http://blog.csdn.net/todaymz/article/details/8958449




抱歉!评论已关闭.