【发布时间】:2011-07-12 14:14:43
【问题描述】:
您好,我希望就以下问题获得一些意见。我是 Hibernate 的新手,我正在努力解决这个问题。
问题:我的数据库中有每天更新一次的数据。我想让我的实体与此同步并刷新它们。我实现了一个 Spring/Quartz 计时器来调用我的休眠实现类来刷新实体。我试图确保每次调用此方法时都会清除所有当前实体,以便刷新它们。最好的方法是什么?
使用与 Spring 集成的 Hibernate 3.2。
建议的解决方案:
- 这是我使用实体管理器来管理它们的地方吗?
我尝试在 Session.flush 命令和 SesionFactory clear 上使用,但它不起作用。
Spring/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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- Defines the hibernate session factory to be used by the hibernate support dao classes -->
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<property name="dataSource" ref="webDataSrc" />
<property name="annotatedClasses">
<list>
<value>test.foo</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="debug">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
</props>
</property>
</bean>
<!-- get the datasource from the context -->
<bean id="webDataSrc" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="java:comp/env/datasource"/>
</bean>
<bean id="daoTxTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="get*">
PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED
</prop>
</props>
</property>
</bean>
<bean name="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="hibernateSessionFactory" />
<property name="singleSession" value="true" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
<property name="nestedTransactionAllowed" value="true" />
</bean>
【问题讨论】:
标签: hibernate