您的位置:首页 > 移动开发

Spring hibernate配置中mappingLocations、mappingDirectoryLocations与mappingJarLocations 区别

2015-12-04 14:23 330 查看
由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好, 

所以,在项目中我一直使用spring的org.springframework.orm.hibernate.LocalSessionFactoryBean来取代hibernate.cfg.xml文件的功能 

LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件:mappingResources、mappingLocations、mappingDirectoryLocations与mappingJarLocations 

他们的区别: 

mappingResources:指定classpath下具体映射文件名 

petclinic.hbm.xml 

mappingLocations:可以指定任何文件路径,并且可以指定前缀:classpath、file等 

/WEB-INF/petclinic.hbm.xml 

classpath:/com/company/domain/petclinic.hbm.xml 

也可以用通配符指定,????*????指定一个文件(路径)名,????**????指定多个文件(路径)名,例如: 

classpath:/com/company/domain/**/maps/*.hbm.xml 

上面的配置是在com/company/domain包下任何maps路径下的hbm.xml文件都被加载为映射文件 

mappingDirectoryLocations:指定映射的文件路径 

mappingJarLocations:指定加载的映射文件在jar文件中 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: