关于java:Hibernate SessionFactory映射未重新加载

Hibernate SessionFactory Mappings is not reloaded

我正在使用带有SessionFactory配置的Hibernate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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映射文件,如下所示:

1
2
3
4
5
6
<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并重新启动PC,但这无济于事。

先谢谢您!


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