-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
Mike Youngstrom opened SPR-114 and commented
If I wrap a simple spring bean into a TransactionInterceptor and aHibernateInterceptor and set all methods to "readonly" and attempt to delete an object using hibernate and then query hibernate again the object is perminately deleted. Conversely if I delete the item and then do not attempt to query hibernate again then the item is correctly not deleted.
TestBean.java
public class TestBean implements Executeable {
public HibernateTemplate hibernateTemplate;
public String execute() {
hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
List accounts = session.find("from KeyValue");
System.out.println(accounts.size());
session.delete(accounts.get(0));
//If you comment out the line below this then everything works as expected.
accounts = session.find("from KeyValue");
System.out.println(accounts.size());
return null;
}
});
return null;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
}
Executeable.java
public interface Executeable {
public String execute();
}
pertinate applicationContext.xml entries.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mySessionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:/hibernate/HibernateFactory</value>
</property>
</bean>
<bean id="myHibernateInterceptor"
class="org.springframework.orm.hibernate.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="mySessionFactory"/>
</property>
</bean>
<bean id="matchAllWithPropReq" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName">
<value>java:/TransactionManager</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>
<bean id="myTransactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributeSource">
<ref local="matchAllWithPropReq"/>
</property>
</bean>
<bean id="Bean1" class="TestBean" singleton="false">
<property name="hibernateTemplate">
<ref local="hibernateTemplate"/>
</property>
</bean>
<bean id="myBean1" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>Executeable</value>
</property>
<property name="interceptorNames">
<list>
<value>myTransactionInterceptor</value>
<value>myHibernateInterceptor</value>
</list>
</property>
<property name="target">
<ref local="Bean1"/>
</property>
</bean>
</beans>Affects: 1.0.1
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply