不重新加载Hibernate SessionFactory映射

时间:2014-10-24 07:52:09

标签: java eclipse spring hibernate tomcat

我正在使用Hibernate和SessionFactory配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="sessionFactory" scope="singleton"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
        <list>
            <value>mappings/File1.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
            <prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            <prop key="show_sql">false</prop>
            <prop key="hbm2ddl.auto">validate</prop>
            <prop key="hibernate.c3p0.min_size">2</prop>
            <prop key="hibernate.c3p0.max_size">3</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.c3p0.idle_test_period">3000</prop>
        </props>
    </property>

</bean>

<bean id="dataSource" scope="singleton"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1529:VIOLET" />
    <property name="username" value="username" />
    <property name="password" value="password" />
</bean>

它可以正常工作,直到我再添加一个XML映射文件,如下所示:

<property name="mappingResources">
    <list>
        <value>mappings/File1.hbm.xml</value>
        <value>mappings/File2.hbm.xml</value>
    </list>
</property>

添加的映射“File2.hbm.xml”完全不受影响。我甚至尝试使用无效名称在“File2.hbm.xml”中设置类,但Hibernate中没有显示错误(当我在“File1.hbm.xml”中执行此操作时,有异常)。

你能告诉我为什么映射“File2.hbm.xml”不受影响吗?我使用Eclipse和Tomcat,它会缓存一些地方。我已经尝试清理Tomcat并重启我的电脑,但它没有用。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

问题是Tomcat缓存了旧的配置文件。清理后(服务器 - &gt;清除Tomcat工作目录),新文件生效。