在整合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/eLW9t9V9z1du+2x+1uX3928rLp1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DCVgZJcbM5SAkV1uzFACRna5EcCg3AhY/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的更多相关文章

  1. [NHibernate]持久化类(Persistent Classes)

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 引言 持久化类是应用程序用来解决商业问题的类(比如,在电子交易程序中的Customer和Orde ...

  2. NHibernate官方文档中文版——持久化类(Persistent Classes)

    持久化类是一个应用程序中的类,主要用来实现业务逻辑(例如,在电商应用中的客户和订单类).持久化类,就像它的名字一样,生命周期短暂并且用来持久化的据库对象实例. 如果这些类的构造能够依照一些简单的原则, ...

  3. unexpected token: * 和 java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to 解决办法

    一.unexpected token: *  的解决办法 首先要搞清楚sql与hql的区别! sql操作的是数据库表,而hql操作的是对象! sql中“select * from table”,而hq ...

  4. [NHibernate]条件查询Criteria Query

    目录 写在前面 文档与系列文章 条件查询 一个例子 总结 写在前面 上篇文章介绍了HQL查询,我个人觉得使用ORM框架就是为了让少些sql,提高开发效率,而再使用HQL就好像还是使用sql,就觉得有点 ...

  5. HQL: The Hibernate Query Language

    Chapter 14. HQL: The Hibernate Query Language 14.1. Case Sensitivity 14.2. The from clause 14.3. Ass ...

  6. Persistent Data Structures

    原文链接:http://www.codeproject.com/Articles/9680/Persistent-Data-Structures Introduction When you hear ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Linux系统——引导过程与服务控制

    一.Linux开机启动原理(十步) (1)开机自检BIOS 开机检测,主板检测 (2)MBR引导 硬盘512字节 (3)GRUB菜单 操作系统菜单 (4)加载内核(kernel) 启动操作系统核心,根 ...

  2. 【JXL】导出Excel

    基本设置 // File file = new File("d:\\writetest.xlsx");// WritableWorkbook wwb = Workbook.crea ...

  3. 在Windows上安装Elasticsearch 5.x

    在Windows上安装Elasticsearch 5.x 自己想学习Elasticsearch,但是又不懂Linux,按照同事给的Linux安装教程,也是搞不明白,于是想先在Windows上安装一下入 ...

  4. HDU 1950 Bridging signals(LIS)

    最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...

  5. spring mvc 全局处理异常

    spring框架支持很多种全局处理异常的方式 一.Spring MVC处理异常有4种方式: (1)使用Spring-MVC提供的SimpleMappingExceptionResolver: (2)实 ...

  6. HTTPS复习

    Https Https其实是两个协议,即HTTP协议和SSL协议,但是由于HTTP协议应用广泛,而且需要为其提供数据隐私保护,所以将HTTP协议与SSL协议结合.HTTP属于应用层,在远古时代,它只需 ...

  7. message from server: "Host '192.168.6.68' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts

    系统或者程序连接数据报错 null, message from server: "Host '192.168.6.68' is blocked because of many connect ...

  8. [原创]css中a标签去掉锚点文本下划线

    我对博客的认识是:记录问题,解决问题,分享知识.如果有轮子,我不需要造轮子. 1.问题解决方式: 设置属性:text-decoration:none; 2.更多属性参数参考 text-decorati ...

  9. ::before ::after CSS3中的伪类和伪元素

    ::before和::after伪元素的用法 一.介绍 css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:target,:not(),:fo ...

  10. The mind

    Youtube励志红人Mateusz M,最近刚推出了网友期待已久最新励志短片<The mind>,短短一周播放量已近50万.来自波兰的他,年仅23岁,用自己擅长的蒙太奇,已创作十几个影响 ...