I have got a a logic class which uses a number of dao's and is configured to use declarative transactions. All my dao's use the spring hibernate dao template. It seems the same hibernate session object is being shared across multiple method calls to the UserLogic class. With the configuration I have I was expecting spring to start a new transaction (and get a new session from the session factory) and then commit transaction if no unchecked exceptions were thrown (and remove the session so it would not be used in future calls). I know I am getting the same session because if I call an update method after a get method I get an exception thrown (below). Has anyone had this problem or am I doing something stupid.
Exception:
-----------------------------------------------------------------------------------------
org.springframework.orm.hibernate.HibernateSystemE xception: a different object with the same identifier value was already associated with the session: 4028a0fe02a16cd00102a16cdd810001, of class: com.shr2shr.world.domain.entity.User; nested exception is net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 4028a0fe02a16cd00102a16cdd810001, of class: com.shr2shr.world.domain.entity.User
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 4028a0fe02a16cd00102a16cdd810001, of class: com.shr2shr.world.domain.entity.User
Spring config
--------------------------------------------------------------------------------------------
<?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="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>hibernate.properties</value>
</list>
</property>
</bean>
<!-- Connection pool and hibernate session factory set up -->
<bean id="WorldDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${hibernate.connection.driver_class}</value>
</property>
<property name="url">
<value>${hibernate.connection.url}</value>
</property>
<property name="username">
<value>${hibernate.connection.username}</value>
</property>
<property name="password">
<value>${hibernate.connection.password}</value>
</property>
</bean>
<bean id="SessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
<property name="dataSource"><ref local="WorldDataSource"/></property>
<property name="mappingResources">
<list>
<value>com/shr2shr/world/domain/entity/User.hbm.xml</value>
<value>com/shr2shr/world/domain/entity/UserGroup.hbm.xml</value>
<value>com/shr2shr/world/domain/entity/Location.hbm.xml</value>
<value>com/shr2shr/world/domain/entity/MenuItem.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.P ostgreSQLDialect</prop>
<prop key="hibernate.query.substitutions">true=1 false=0</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Transaction manager and interecptor set up -->
<bean id="TransactionManager"
class="org.springframework.orm.hibernate.Hibernate TransactionManager">
<property name="sessionFactory"><ref local="SessionFactory"/></property>
</bean>
<bean id="BaseTransactionProxy" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager"><ref bean="TransactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- Dao config -->
<bean id="UserDao" class="com.shr2shr.world.domain.dao.hibernate.User DaoHibernate">
<property name="sessionFactory"><ref local="SessionFactory"/></property>
</bean>
<bean id="UserGroupDao" class="com.shr2shr.world.domain.dao.hibernate.User GroupDaoHibernate">
<property name="sessionFactory"><ref local="SessionFactory"/></property>
</bean>
<bean id="MenuItemDao" class="com.shr2shr.world.domain.dao.hibernate.Menu ItemDaoHibernate">
<property name="sessionFactory"><ref local="SessionFactory"/></property>
</bean>
<!-- Logic config -->
<bean id="UserLogic" parent="BaseTransactionProxy">
<property name="target">
<bean class="com.shr2shr.world.domain.logic.UserLogicImp l">
<constructor-arg index="0"><ref local="UserDao"/></constructor-arg>
<constructor-arg index="1"><ref local="UserGroupDao"/></constructor-arg>
<constructor-arg index="2"><ref local="MenuItemDao"/></constructor-arg>
</bean>
</property>
</bean>
</beans>


Reply With Quote