[perfectjpattern-users] Using AbstractJpaManagedBaseDao with spring and JTA
Brought to you by:
bravegag
From: Mansour Al A. <man...@gm...> - 2012-08-12 15:47:08
|
I am trying to setup a project to use Spring and AbstractJpaManagedBaseDao. I am unable to setup the transaction to work properly. I need to have control over the transaction so I am using "RESOURCE_LOCAL". Here's the relevant part of my setup (if something is missing, please let me know): <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:META-INF/database.properties</value> </list> </property> </bean> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://localhost/mydb" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="vendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="altabank" /> <property name="jpaVendorAdapter" ref="vendorAdapter" /> </bean> <bean id="dao" class="com.example.services.CategoryDao" /> @Test public void testUpdate() { ProductCategory category = new ProductCategory(); category.setCategoryName("Weight Loose"); category.setDescription("Products that helps in loosing weight"); // dao.getTransaction().begin(); String id = dao.create(category); // dao.getTransaction().commit(); assertNotNull(id); } In the debug messages, I am getting: DEBUG [main] (StatefulPersistenceContext.java:899) - Initializing non-lazy collections DEBUG [main] (Loader.java:2070) - Done entity load DEBUG [main] (ExtendedEntityManagerCreator.java:404) - No local transaction to join DEBUG [main] (SqlStatementLogger.java:104) - select nextval ('hibernate_sequence') Hibernate: select nextval ('hibernate_sequence') DEBUG [main] (AbstractEntityManagerImpl.java:1131) - Mark transaction for rollback Additionally, when I try to change the transaction to JTA instead of RESOURCE_LOCAL, I don't see any dao executed. Any advice ?? Thank you. |