Frage

Tried to configure Spring for tests with hibernate and transactions. Getting bean from app context which is marked with @Transactional transaction isn't intercepted. What I could miss in configuration?

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
    <property name="dataSource" ref="dataSource"></property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<import resource="spring-dao.xml"/>

<tx:annotation-driven transaction-manager="transactionManager" />


<bean id="userService" class="com.test.service.UserServiceimpl">
    <property name="userDao" ref="userDao"/>
</bean>

public interface UserService {

public abstract User loadUserById(long userId);

@Transactional
public abstract void doSomething();

}

public class UserServiceimpl implements UserService {
@Override
public void doSomething() {
    User user = loadUserById(1);
    user.fillUpMoney(999);
    userDao.update(user);
    throw new RuntimeException("Shpould be rollback");
}
War es hilfreich?

Andere Tipps

Don't annotate the abstract method as transactional, annotate the concrete implementation.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top