Declarative spring transactions not being committed

Ekaros

New Member
I have the following service classes:\[code\]public class UserLoginServiceImpl implements UserLoginService { private UserDAO dao; public UserLoginServiceImpl(UserDAO dao) {this.dao = dao; } public User login(String userName, String password) { User u = dao.findUserByCredentials(userName, password); if (u == null) { throw new UserNotFoundException(); } return u;}public class UserManagementServiceImpl implements UserManagementService { private UserDAO dao; public UserManagementServiceImpl(UserDAO dao) { this.dao = dao; } public void createUser(User u) { dao.save(u); }}\[/code\]My service interfaces reside under com.mysystem.services package and my service implementations under com.mysystem.services.impl package.I am using hibernate as my jpa implementation and declarative transactions in spring. My configuration file is the following: \[code\]<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"><property name="entityManagerFactory" ref="entityManagerFactory"/></bean><tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*"/> </tx:attributes></tx:advice><aop:config> <aop:pointcut id="serviceMethod" expression="execution(* com.mysystem.services.impl.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/></aop:config><!-- Beans --><bean id="userDao" class="com.mysystem.dao.UserDAOImpl"> <constructor-arg ref="entityManagerFactory" /></bean><bean id="userLoginService" class="com.mysystem.services.impl.UserLoginServiceImpl"> <constructor-arg ref="userDao" /></bean><bean id="userManagementService" class="com.mysystem.services.impl.UserManagementServiceImpl"> <constructor-arg ref="userDao" /></bean>\[/code\]Lastly, somewhere in my code i run the following:\[code\]UserManagementService userManagementService = context.getBean(UserManagementService.class);userManagementService.createUser(new User("test", "test"));UserLoginService userLogginService = context.getBean(UserLoginService.class);User user = userLogginService.login("test", "test");\[/code\]which results in the login() method throwing an UserNotFoundException because it cannot find the user inserted by createUser() previously which means that hibernate will not flush the session between method calls. I can verify this form the console output (i can see hibernate's create and select statements but not insert).Why isn't the transaction committed soon after the call to createUser()? What am i doing wrong here?EDIT:Using the @Transactional annotation instead of declarative transactions works. Using @Transactional however is not an option for me. I need to implement declarative transactions.Below is the spring's debug output:\[code\]13:03:18,174 DEBUG [main] jpa.JpaTransactionManager - Creating new transaction with name [com.mysystem.services.impl.UserManagementServiceImpl.createUser]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT13:03:18,175 DEBUG [main] jpa.JpaTransactionManager - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711] for JPA transactionHibernate: select nextval ('hibernate_sequence')13:03:18,255 DEBUG [main] jpa.JpaTransactionManager - Initiating transaction commit13:03:18,255 DEBUG [main] jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711]13:03:18,256 DEBUG [main] jpa.JpaTransactionManager - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711] after transaction 13:03:18,263 DEBUG [main] jpa.JpaTransactionManager - Creating new transaction with name [com.mysystem.services.impl.UserLoginServiceImpl.login]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT 13:03:18,263 DEBUG [main] jpa.JpaTransactionManager - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd] for JPA transaction Hibernate: /* from com.mysystem.domain.User u where u.userName = :userName and u.password = :password */ select user0_.id as id0_, user0_.password as password0_, user0_.userName as userName0_ from Users user0_ where user0_.userName=? and user0_.password=? limit ? 13:03:18,374 TRACE [main] sql.BasicBinder - binding parameter [1] as [VARCHAR] - test 13:03:18,374 TRACE [main] sql.BasicBinder - binding parameter [2] as [VARCHAR] - test 13:03:18,379 DEBUG [main] jpa.JpaTransactionManager - Initiating transaction commit 13:03:18,379 DEBUG [main] jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd] 13:03:18,379 DEBUG [main] jpa.JpaTransactionManager - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd] after transaction\[/code\]
 
Top