【发布时间】: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