Spring + Hibernate 的配置问题 你说的配成多个文件是把哪个文件配成多个呀,你要是只觉得hibernate的映射文件太多,不想放spring的XML里可以用hibernate自己的XML也是一样的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用<property name="mappingDirectoryLocations"> <list> <value>classpath:.....</value> </list> </property> 我想把hibernate的or映射文件的配置部分分成多个文件放在ApplicationContex.xml外面,楼上的能不能具体点。。<value>classpath:.....</value>是配置路径还是hbm.xml? Spring:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean>Hibernate:<mapping resource="com/xxx0.hbm.xml" /><mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" /> 我怎么把<mapping resource="com/xxx0.hbm.xml" /><mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />分成多个部分?放到多个文件中? classpath:.... 是你文件的路径 比如:<property name="mappingDirectoryLocations"> <list> <value>classpath:/com/myconf/</value> </list></property> 恩这样写就行<property name="mappingDirectoryLocations"> <list> <value>classpath:/com/myconf/</value> </list></property> <property name="mappingDirectoryLocations"><list><value>classpath:/com/myconf/</value></list></property>classpath:/com/myconf/ 是什么?里面是什么东西我怎么把原来的<mapping resource="com/xxx0.hbm.xml" /><mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />分成多个部分?放到多个文件中?各位大哥能具体点不? classpath里面就是你的那些xxx.hbm.xml文件 classpath里面就是你的那些xxx.hbm.xml文件可是我的那些xxx.hbm.xml文件在不同的包下面啊<list><value>classpath:/com/myconf/</value></list>这个value是path?有没有高手给个详细的配置 给楼主看看我的配置方法Spring.....<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="configLocation"> <value>/WEB-INF/hibernate.cfg.xml</value> </property> </bean>.....hibernate.cfg.xml..... <mapping resource="com/zqp/test/pojo/Dept.hbm.xml"/> <mapping resource="com/zqp/pojo/Income.hbm.xml"/> <mapping resource="com/zqp/pojo/Cost.hbm.xml"/> <mapping resource="com/zqp/pojo/Admin.hbm.xml"/> <mapping resource="com/zqp/pojo/Player.hbm.xml"/> <mapping resource="com/zqp/pojo/Coach.hbm.xml"/>.... 谢谢楼上的,但是我现在要把这些东西分成多块放在不同的文件里面怎么做?.....<mapping resource="com/zqp/test/pojo/Dept.hbm.xml"/><mapping resource="com/zqp/pojo/Income.hbm.xml"/><mapping resource="com/zqp/pojo/Cost.hbm.xml"/><mapping resource="com/zqp/pojo/Admin.hbm.xml"/><mapping resource="com/zqp/pojo/Player.hbm.xml"/><mapping resource="com/zqp/pojo/Coach.hbm.xml"/>.... 我怎么看不太明白你们写的,不就是写两个XML文件? 1) Model.hbm.xml 2) hibernate.cfg.xml里面也不是那样写的呀? 我怎么看不太明白你们写的,不就是写两个XML文件?1) Model.hbm.xml2) hibernate.cfg.xml里面也不是那样写的呀?1) Model.hbm.xml 这是or映射的文件2) hibernate.cfg.xml 这是hibernate的配置文件,里面指定了一批or映射,我想把这一批又分成多个部分。 分成多块的话 <property name="configLocation"> <value>/WEB-INF/hibernate.cfg.xml</value> </property>改成 <property name="configLocation"> <value>/WEB-INF/hibernate.cfg.xml,/XXX/XXX/XXX.cfg.xml</value> </property> 谢谢zqpsswh(似水无痕) 好像这是我想要的。 <property name="mappingDirectoryLocations"> <list> <value>classpath:/com/myconf/</value> <value>classpath:/com/myconf2/</value> .... </list></property>这里/com/myconf/,/com/myconf2就是你放xxx.hbm.xml的目录 用spring的配置文件就可以了,不用再去写hibernate.cfg.xml了 谢谢 Daem0n(瓶中的精灵) 我的意思是把<value>classpath:/com/myconf/</value><value>classpath:/com/myconf2/</value>....这些配置放在不同的文件中,不是spring的xml中,因为太多了。 楼主的意思不就是觉得xxx.hbm.xml太多了,在spring里面写:<mapping resource="com/xxx0.hbm.xml" /><mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />太麻烦吗? 据说可以domain/*/*.hbm.xml使用通配符,不过要求把hbm放到一个文件夹下 字符串匹配问题?? Hibernate 添加监听器问题 java邮件发送 关于hibernate+spring整合问题? hibernate的HQL查询和本地化查询有什么根本的区别? 高手进来:怎样得到一个表中的某个字段的字段类型 任何做和浏览器一样的前进后退按钮 急!! 在JAVA中如何用代码关闭一个窗体?不再使用的全局对象如何清理呢?我是新手请多指教! 我下载这个怎么不能打开 请教JBoss连接Qracle的问题 whyfdsfdsafdsa 菜鸟MM求助高手们!!!急!!!
<list>
<value>classpath:.....</value>
</list>
</property>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>Hibernate:
<mapping resource="com/xxx0.hbm.xml" />
<mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />
<mapping resource="com/xxx0.hbm.xml" />
<mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />
分成多个部分?放到多个文件中?
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/myconf/</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/myconf/</value>
</list>
</property>
<list>
<value>classpath:/com/myconf/</value>
</list>
</property>
classpath:/com/myconf/ 是什么?里面是什么东西
我怎么把原来的
<mapping resource="com/xxx0.hbm.xml" />
<mapping resource="com/xxx1.hbm.xml" /><mapping resource="com/xxx2.hbm.xml" /><mapping resource="com/xxx3.hbm.xml" />
分成多个部分?放到多个文件中?各位大哥能具体点不?
可是我的那些xxx.hbm.xml文件在不同的包下面啊<list>
<value>classpath:/com/myconf/</value>
</list>
这个value是path?
有没有高手给个详细的配置
Spring
.....
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
</bean>
.....hibernate.cfg.xml
.....
<mapping resource="com/zqp/test/pojo/Dept.hbm.xml"/>
<mapping resource="com/zqp/pojo/Income.hbm.xml"/>
<mapping resource="com/zqp/pojo/Cost.hbm.xml"/>
<mapping resource="com/zqp/pojo/Admin.hbm.xml"/>
<mapping resource="com/zqp/pojo/Player.hbm.xml"/>
<mapping resource="com/zqp/pojo/Coach.hbm.xml"/>
....
<mapping resource="com/zqp/test/pojo/Dept.hbm.xml"/>
<mapping resource="com/zqp/pojo/Income.hbm.xml"/>
<mapping resource="com/zqp/pojo/Cost.hbm.xml"/>
<mapping resource="com/zqp/pojo/Admin.hbm.xml"/>
<mapping resource="com/zqp/pojo/Player.hbm.xml"/>
<mapping resource="com/zqp/pojo/Coach.hbm.xml"/>
....
1) Model.hbm.xml
2) hibernate.cfg.xml
里面也不是那样写的呀?
1) Model.hbm.xml
2) hibernate.cfg.xml
里面也不是那样写的呀?
1) Model.hbm.xml 这是or映射的文件
2) hibernate.cfg.xml 这是hibernate的配置文件,里面指定了一批or映射,我想把这一批又分成多个部分。
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
改成
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml,/XXX/XXX/XXX.cfg.xml</value>
</property>
<list>
<value>classpath:/com/myconf/</value>
<value>classpath:/com/myconf2/</value>
....
</list>
</property>
这里/com/myconf/,/com/myconf2就是你放xxx.hbm.xml的目录
我的意思是把
<value>classpath:/com/myconf/</value>
<value>classpath:/com/myconf2/</value>
....
这些配置放在不同的文件中,不是spring的xml中,因为太多了。
<mapping resource="com/xxx0.hbm.xml" />
<mapping resource="com/xxx1.hbm.xml" />
<mapping resource="com/xxx2.hbm.xml" />
<mapping resource="com/xxx3.hbm.xml" />
太麻烦吗?
domain/*/*.hbm.xml使用通配符,不过要求把hbm放到一个文件夹下