开发一个大一点的项目有很多的hbm.xml文件,有时候上百个也不稀奇,如果用

        <property name="mappingLocations">
<list>
<value>com/tz/entity/Student.hbm.xml</value>
</list>
</property>

那么每一个hbm.xml文件都要配置一行代码,一百个hbm.xml就要写100行 文件让程序 的可读性,可维护性都变都非常差。

一个解决方法就是使用

  <property name="mappingDirectoryLocations">
<list>
//WEB-INF/map 里存放了所有的hbm.xml文件
<value>WEB-INF/map</value>
</list>
</property>

还有一个属性是mappingLocations:可以指定任何文件路径,并且可以指定前缀:classpath,file等

 <property name="mappingLocations">
<list>
//WEB-INF/map 里存放了所有的hbm.xml文件
<value>/com/tz/entity/student.hbm.xml</value>
</list>
</property>

也可以

 <property name="mappingDirectoryLocations">
<list>
//WEB-INF/map 里存放了所有的hbm.xml文件
<value>classpath:/com/tz/entity/student.hbm.xml</value>
</list>
</property>

  

Spring,Hibernate 集成解决多hbm.xml文件繁多的方案的更多相关文章

  1. 通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件

    1.   前言 很多人都在使用myEclipse,很多公司也都使用hibernate框架,老版本的hibernate中,由于没有annotation,我们需要写两个文件来维护表与对象的关系,写一个类, ...

  2. intellij配置hibernate自动生成hbm.xml文件

    1.首先创建一个Java web项目,这里因为已经在整个项目中配置好tomcat了,所以我是直接创建module的,其实和创建project的配置方法一样,创建的时候选择Web Application ...

  3. hibernate.hbm.xml文件配置入门小结(1)

    在Hibernate中,各表的映射文件xxx.hbm.xml可以通过工具生成,例如在使用MyEclipse开发时,它提供了自动生成映射文件的工具. hibernate.hbm.xml文件的基本结构如下 ...

  4. hibernate的.hbm.xml文件文件配置属性详解

    一般.hbm.xml文件如下面: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "- ...

  5. 在spring中映射X.hbm.xml文件的小技巧

    通常在spring中会这么写代码: <bean id="sessionFactory" class="org.springframework.orm.hiberna ...

  6. Maven项目不打包*.hbm.xml文件

    <build> <finalName>basic</finalName> <plugins> <plugin> <groupId> ...

  7. Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

    Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

  8. intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件

    1. 错误信息 Invocation of init method failed; nested exception is org.hibernate.MappingNotFoundException ...

  9. Spring Boot 集成阿里云 OSS 进行文件存储

    最近因为项目中需要存储很多的图片,不想存储到服务器上,因此就直接选用阿里云的对象服务(Object Storage Service,简称 OSS)来进行存储,本文将介绍 Spring Boot 集成 ...

随机推荐

  1. Microsoft Dynamics CRM 2011 面向Internet部署 (IFD) CRM 登录出现会话超时的解决办法

    一.IFD 登录的时候,过了一段时间,会马上出现“您的会话已过期”,怎么解决这个问题呢,可以通过改变这个时间.具体图如二 Link to Dynamics CRM Wiki Home Page 二.S ...

  2. 启动servlet报错:The servlets named [DemoServlet] and [main.java.com.wlf.demo.servlet.DemoServlet] are both mapped to the url-pattern [/hello] which is not permitted

    先看具体错误日志: [2019-04-26 09:29:25,484] Artifact demo-servlet:war: Artifact is being deployed, please wa ...

  3. 【python】class之super关键字的作用

    在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1: 代码段1: class A: def __init__(self):    prin ...

  4. android datepicker monthOfYear getMonth(): 获取当前月(注意:返回数值为0..11,需要自己+1来显示).....

    关键点: 1. getMonth():     获取当前月(注意:返回数值为0..11,需要自己+1来显示) 2. 初始年(译者注:注意使用new Date()初始化年时,需要+1900,如下:dat ...

  5. innodb的锁、update单条记录的花费时间压测

    观察innodb的锁时间,需要关注: mysqladmin extended-status -r -i 1 -uroot | grep "Innodb_row_lock_time" ...

  6. 使用postman模拟appium的http请求

    Appium是Server,接收http请求,使用Postman模拟请求 1.anyproxy 1.1.安装和运行 #安装 npm i -g anyproxy # 运行anyproxy,端口默认800 ...

  7. GC 提前晋升

    如果Survivor 空间不足, 那么从 Eden 存活下来的和原来在 Survivor 空间中不够老的对象占满 Survivor 后, 就会提升到老年代, 可以看到这一轮 Minor GC 后老年代 ...

  8. 共享存储(ISCSI网络存储)

    server端:(192.168.100.11) 分区sdb 分别为10G和5G #fdisk /dev/dab …… 同步分区表 #partprobe /dev/sdb # yum install ...

  9. zabbix批量添加SNMP监听H3C端口检测以及流量图

    由于之前网络设备不是很多,监控网络设备接口就直接使用模版中的item来实现了,可是现在公司上线了一大批网络设备,如果要每个网络设备都做模板,添加item......那就该废了,于是迫于压力今天来测试使 ...

  10. 自己根据js的兼容封装了一个小小的js库

    var gys = function () { } //oParent父节点 //获取所有的子元素 gys.prototype.getElementChildren = function (oPare ...