no persistent classes found for query class: FROM com.vrv.paw.domain.User
在整合Spring+Hibernate时报该错误,sessionFactory配置如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
.......
<!-- 自动扫描注解方式配置的hibernate类文件 -->
<property name="packagesToScan"> //最后发现是该处的错误
<list>
<value>sys.model</value>
</list>
</property>
.......
</bean>
正如上面XML配置的那样,packageToScan是配置以注解方式配置Hibernate类,即如下这样的方式:
package sys.model; import java.io.Serializable;
import java.util.Date; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType; @Entity
@Table(name = "User")
public class UserInfo implements Serializable {
private static final long serialVersionUID = 8427996478439081619L;
// Fields
private String id;
private String name;
private String pwd;
private Date createdatetime;
private Date modifydatetime;
/** full constructor */
public UserInfo(String id, String name, String pwd, Date createdatetime, Date modifydatetime) {
this.id = id;
this.name = name;
this.pwd = pwd;
this.createdatetime = createdatetime;
this.modifydatetime = modifydatetime;
} @Id
@Column(name = "ID", unique = true, nullable = false, length = 36)
public String getId() {
return this.id;
} public void setId(String id) {
this.id = id;
} @Column(name = "NAME", unique = true, nullable = false, length = 100)
public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} @Column(name = "PWD", nullable = false, length = 32)
public String getPwd() {
return this.pwd;
} public void setPwd(String pwd) {
this.pwd = pwd;
} @Temporal(TemporalType.TIMESTAMP)
// 如果这里是这种TemporalType.DATE,那么时间在数据库中存的时候会是"2015-07-16 00:00:00"这种形式,时分秒都为零
@Column(name = "CREATEDATETIME", length = 7)
public Date getCreatedatetime() {
return this.createdatetime;
} public void setCreatedatetime(Date createdatetime) {
this.createdatetime = createdatetime;
} @Temporal(TemporalType.TIMESTAMP)
@Column(name = "MODIFYDATETIME", length = 7)
public Date getModifydatetime() {
return this.modifydatetime;
} public void setModifydatetime(Date modifydatetime) {
this.modifydatetime = modifydatetime;
} @Override
public String toString() {
return "[ID:" + id + " Name:" + name + " PassWord:" + pwd + " Createdatetime:" + createdatetime + " Modifydatetiem:" + modifydatetime + "]";
}
}
但是我整合式采用的*.hbm.xml的方式
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPQAAAC3CAIAAACqgeRrAAAPoElEQVR4nO2d/XMURRrH59/hl9R5xqiDUrnT02hxUuTKe7HMmYNzPAl6VcQzkMJEoonAIcwlqCFGEwwsSjBELKd8ASPUWawQ9EQ8LdY7IMaCJEBxAZJ9g74fZnemu6dnstnMzsw+/Xyqi9rpdM/2sp+d7dmd77ZiHBwl5U9y+vK1qXGrrFl2L72Zuj4d9gALJKGrimaEPQofiMQDUWDIzXFp4kLYQ0DCB6bcCEJQbgQw5Sr3iQtYyqmEAsqNJYgSCig3liBKKKDcWIIooQBT7nUr/xj60xnFEtOUSn3Y993G9QpFbYx7tQkFIHIf2bTi8KYVhzevOLxpxeFNKxruuZXePLJtVfhiRaGg3OFy8+bNOWuIQ+5D7Su+Hmr5zmj/Zn/r0Z5VGx+55+uh57432r/Z3/p596pD7fXhixWFUiK5CyihEC25+/r6mpqaMpmMVZPJZJqamvr7+7mW3P/dR88/du5Yz9T3sR9He78abB5Y8/C5L3ZMfR/78UTvaKzp4w114YsVhYJyh0U2m21qaqqurrb8Ns02a7LZLN2Y+7/7YP2jp0f0seOv/3C489iuv3X9+cHc5pGueP8a47lH3P/fjVolR0VbgqtRFK3TbqY2xvQKRVEUpTZGTsQ0tpdZEo2Vds1wm6pU6sMXEo2VSm3MqFUUpVKrFTRguudaWndk/imeu2ursrOOGXCupUBf+uEo1F+LfZiOkZyI6xW5PRi1itrYJvifCYUIyU0ISafTls0zMzOc6zSco+81/SE+sHZ0b0t817pD/3i87eHqowNrR/e2fLF73cGtK99f93sPs1k72ZqYpthPW94M8/muM9jn1Xl0NE3N3bAFEjRg5GZa5m4nGuvyUuYrh9vU3BhiWkWlao6ZMt5+ONZddNZZchf9MAUjYeWmu9gT8VCIltyEOlovXbrUzWzCyv3UsvtX/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93gf7uEO58UnGPOW26MUc4X2eXGDCVgZJcbM5SAkV1uzFACRna5EcCg3AhY/g+fwimj+8WqCQAAAABJRU5ErkJggg==" alt="" />
这种方式最方便的方式是采用“mappingDirectoryLocations”
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
.......
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/vrv/paw/domain</value>
</list>
</property>
</bean>
扩展:
mappingResources、mappingLocations、mappingDirectoryLocations
他们的区别:
1. mappingResources:指定classpath下具体映射文件名
<property name="mappingResources">
<value>petclinic.hbm.xml </value>
</property>
2. mappingLocations:可以指定任何文件路径,并且可以指定前缀:classpath、file等
<property name="mappingLocations">
<value>/WEB-INF/petclinic.hbm.xml </value>
</property>
<property name="mappingLocations">
<value>classpath:/com/company/domain/petclinic.hbm.xml </value>
</property>
也可以用通配符指定,'*'指定一个文件(路径)名,'**'指定多个文件(路径)名,例如:
<property name="mappingLocations">
<value>classpath:/com/company/domainmaps/*.hbm.xml </value>
</property>
上面的配置是在com/company/domain包下任何maps路径下的hbm.xml文件都被加载为映射文件
3. mappingDirectoryLocations:指定映射的文件路径
<property name="mappingDirectoryLocations"> <list>
<value>WEB-INF/HibernateMappings</value>
</list>
</property>
也可以通过classpath来指出
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/XXX/package/</value>
</list>
</property>
总结:注解方式配置的hibernate类 与 *.hbm.xml 方式配置的类,在配置SessionFactory时配置方式是不同的,这是我以前没有注意的
no persistent classes found for query class: FROM com.vrv.paw.domain.User的更多相关文章
- [NHibernate]持久化类(Persistent Classes)
系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 引言 持久化类是应用程序用来解决商业问题的类(比如,在电子交易程序中的Customer和Orde ...
- NHibernate官方文档中文版——持久化类(Persistent Classes)
持久化类是一个应用程序中的类,主要用来实现业务逻辑(例如,在电商应用中的客户和订单类).持久化类,就像它的名字一样,生命周期短暂并且用来持久化的据库对象实例. 如果这些类的构造能够依照一些简单的原则, ...
- unexpected token: * 和 java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to 解决办法
一.unexpected token: * 的解决办法 首先要搞清楚sql与hql的区别! sql操作的是数据库表,而hql操作的是对象! sql中“select * from table”,而hq ...
- [NHibernate]条件查询Criteria Query
目录 写在前面 文档与系列文章 条件查询 一个例子 总结 写在前面 上篇文章介绍了HQL查询,我个人觉得使用ORM框架就是为了让少些sql,提高开发效率,而再使用HQL就好像还是使用sql,就觉得有点 ...
- HQL: The Hibernate Query Language
Chapter 14. HQL: The Hibernate Query Language 14.1. Case Sensitivity 14.2. The from clause 14.3. Ass ...
- Persistent Data Structures
原文链接:http://www.codeproject.com/Articles/9680/Persistent-Data-Structures Introduction When you hear ...
- How to: Generate XPO Business Classes for Existing Data Tables 如何:为现有数据表生成 XPO 业务类
From the Tutorial and other documentation sources, you learned how to create business classes for yo ...
- How to: Implement a Custom Base Persistent Class 如何:实现自定义持久化基类
XAF ships with the Business Class Library that contains a number of persistent classes ready for use ...
- Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)
In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...
随机推荐
- PHP连接MYSQL操作数据库
PHP连接MYSQL操作数据库 <?php $con = mysql_connect("localhost","root",""); ...
- PHP计算上一个月最后一天、当月最后一天、下一个月最后一天
上个月最后一天: $last_month_last_day = date('Y-m-t',strtotime('-1 month')); 当月最后一天: $first_day=date('Y-m-01 ...
- Mac使用操作
快捷键退出程序:Command + Q 快捷键关闭窗口:Command + W(关闭程序的窗口不一定是退出程序) 单击左上角黑苹果,菜单里面有强制退出 Finder菜单的偏好设置,高级设置菜单里面可以 ...
- [笔记] Ubuntu 18.04安装Docker CE及nvidia-docker2流程
Docker的好处之一,就是在Container里面可以随意瞎搞,不用担心弄崩Host的环境. 而nvidia-docker2的好处是NVidia帮你配好了Host和Container之间的CUDA相 ...
- 高并发下hystrix熔断超时及concurrent.RejectedExecutionException: Rejected command because thread-pool queueSize is at rejection threshold问题
我的一个项目并发200+,观察服务器的日志发现出现了大量的熔断超时偶尔会闪现出RejectedExecutionException: Rejected command because thread-p ...
- JPush相关概念
JPush相关概念 连接极光服务器前提 在连接极光服务器之前需要先将APP进行注册,连接Server时需要用到下发的两个字段:AppKey:应用唯一标识.Master Secret:服务器秘钥,用于服 ...
- bootstrap常用知识点总结
api地址:https://v3.bootcss.com/css/#forms 栅格参数: bootstrap 其实 是把 网页等 分为 了 12分,bootstrap把 根据屏 幕 大小 把屏 幕分 ...
- spring boot 总结
一.什么是SpringBoot 描述:Spring Boot是Spring社区发布的一个开源项目,旨在帮助开发者快速并且更简单的构建项目.大多数SpringBoot项目只需要很少的配置文件.二.Spr ...
- 2017浙江省赛 C - What Kind of Friends Are You? ZOJ - 3960
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960 题目: Japari Park is a large zoo ...
- MySql中concat函数的用法(链接字符串)
MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...