【问题标题】:Hibernate SessionFactory Mappings is not reloadedHibernate SessionFactory Mappings 未重新加载
【发布时间】:2014-10-24 07:52:09
【问题描述】:

我在这个 SessionFactory 配置中使用 Hibernate

<?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 并重新启动我的电脑,但它没有帮助。

提前谢谢你!

【问题讨论】:

  • 您有hibernate.cfg.xml 文件吗?此外,如果您使用 spring,则您的配置有缺陷永远不要设置 hibernate.current_session_context_class,将其设置为线程会破坏正确的 tx 管理(如果您使用的是 springs tx 管理)。另请注意,hibernate.c3p0 属性是无用的,因为您正在自己注入 DataSource
  • 其实问题不在于配置文件。正如我所提到的,我的代码有效,但只有 File2.hbm.xml 不受影响。我清理了tomcat工作目录,问题解决了
  • 它工作的事实并不意味着它是正确的:) 但唉。只是想指出您的配置缺陷并要求澄清。

标签: java eclipse spring hibernate tomcat


【解决方案1】:

问题是 Tomcat 缓存了旧的配置文件。清理后(Server -> Clean Tomcat Work Directory),新文件生效。

【讨论】:

    猜你喜欢
    • 2019-06-04
    • 2012-01-24
    • 1970-01-01
    • 2023-03-21
    • 2012-12-08
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多