spring+hibernate,我在pojo映射文件中配置了延迟加载,在application.xml中对DAO配置代理,来解决延迟加载问题,配置如下:
<bean name="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="JJxcJhthDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref bean="JxcJhthDAO"/></property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="interceptorNames">
<list>
<value>openSessionInViewInterceptor</value>
</list>
</property>
</bean>
<bean id="JxcJhthDAO" class="com.tx.dao.JxcJhthDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
程序运行没有问题,但是,我发现我需要在jxcjhthdao上加声明事务,这个时候,我找到原来的声明事务部分.如下:
<bean id="JJxcJhthDAO"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="target">
<ref local="TestoDAO"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="save">
PROPAGATION_REQUIRED
</prop>
<prop key="findByProperty">
PROPAGATION_REQUIRED
</prop>
</props>
</property>
</bean>
这下,我迷糊了,如何把 控制session生命周期的接口和事务接口都放到一个dao中? 也就是如何把这两个实现不同功能的代理类配置合并起来? 请教各位帮小弟看看.谢谢了
<bean name="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="JJxcJhthDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref bean="JxcJhthDAO"/></property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="interceptorNames">
<list>
<value>openSessionInViewInterceptor</value>
</list>
</property>
</bean>
<bean id="JxcJhthDAO" class="com.tx.dao.JxcJhthDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
程序运行没有问题,但是,我发现我需要在jxcjhthdao上加声明事务,这个时候,我找到原来的声明事务部分.如下:
<bean id="JJxcJhthDAO"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="target">
<ref local="TestoDAO"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="save">
PROPAGATION_REQUIRED
</prop>
<prop key="findByProperty">
PROPAGATION_REQUIRED
</prop>
</props>
</property>
</bean>
这下,我迷糊了,如何把 控制session生命周期的接口和事务接口都放到一个dao中? 也就是如何把这两个实现不同功能的代理类配置合并起来? 请教各位帮小弟看看.谢谢了