Announcement Announcement Module
Collapse
No announcement yet.
TransactionRequiredException: no transaction is in progress Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionRequiredException: no transaction is in progress

    Hello,

    I am quiet new in the Spring environment and struggle around in seting up web project wich uses in the service layer Spring 3.0.2, Hibernate JPA, XA from Atomikos, a PostgreSQL Database and a DB2/400 Database.

    My Problem is, I always get "javax.persistence.TransactionRequiredExceptio n: no transaction is in progress" Exceptions, when I call entityManager.flush() in my DAO Objects.

    The wired thing is, when I debug through the call of my Service method (which is @Transactional annotated), I can see how the transaction is bound to the thread! But when the dao method is reached, obvious no Transaction is active anymore.

    Now my code and configuration:

    service.spring.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/aop
                http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    
    	<!-- JPA Setup -->
    	<!--================================================= -->
    	<!-- XA DataSource Versuch -->
    	<!--================================================= -->
    	<!-- AS 400 DB2 XA datasources -->
    	<bean id="DatenAs400Db2XaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    		init-method="init" destroy-method="close">
    		<property name="uniqueResourceName" value="datenas400db2" />
    		<property name="xaDataSourceClassName">
    			<value>com.ibm.as400.access.AS400JDBCXADataSource</value>
    		</property>
    		<property name="xaProperties">
    			<props>
    				<prop key="databaseName">dxyz</prop>
    				<prop key="serverName">10.xxx.xxxx.xx</prop>
    				<!-- <prop key="port">8471</prop> -->
    				<prop key="user">*****</prop>
    				<prop key="password">*****</prop>
    			</props>
    		</property>
    		<property name="minPoolSize" value="1" />
    	</bean>
    
    	<!-- SessionFactory for as 400 db2 daten -->
    	<bean id="sessionFactoryAs400Db2Daten"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="useTransactionAwareDataSource" value="true" />
    		<property name="dataSource">
    			<ref bean="DatenAs400Db2XaDataSource" />
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.DB2400Dialect</prop>
    				<prop key="hibernate.connection.isolation">3</prop>
    				<prop key="hibernate.current_session_context_class">jta</prop>
    				<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
    				</prop>
    				<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
    				</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
    			</props>
    		</property>
    	</bean>
    
    	<!-- XA datasource for the PostgreSQL context -->
    	<bean id="PostgreSqlXaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    		init-method="init" destroy-method="close">
    		<property name="uniqueResourceName" value="postgresql" />
    		<property name="xaDataSourceClassName" value="org.postgresql.xa.PGXADataSource" />
    		<property name="xaProperties">
    			<props>
    				<prop key="databaseName">dls</prop>
    				<prop key="serverName">10.xxxx.xxx.xx</prop>
    				<prop key="databaseName">xyx</prop>
    				<prop key="portNumber">5432</prop>
    				<prop key="user">****</prop>
    				<prop key="password">****</prop>
    			</props>
    		</property>
    		<property name="minPoolSize" value="1" />
    	</bean>
    
    	<!-- SessionFactory for the prosocForum context -->
    	<bean id="sessionFactoryPostgreSql"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="useTransactionAwareDataSource" value="true" />
    		<property name="dataSource">
    			<ref bean="PostgreSqlXaDataSource" />
    		</property>
    		<!-- <property name="mappingResources"> <list> <value>uk/co/prodia/prosoc/forum/mvnforum/MVNForumMember.hbm.xml</value> 
    			</list> </property> -->
    		<property name="hibernateProperties">
    			<props>
    				<!-- If hibernate.dialect causes a problem switch it to org.hibernate.dialect.MySQLDialect -->
    				<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
    				<prop key="hibernate.connection.isolation">3</prop>
    				<prop key="hibernate.current_session_context_class">jta</prop>
    				<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
    				</prop>
    				<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
    				</prop>
    				<prop key="hibernate.show_sql">true</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="pum"
    		class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    		<property name="persistenceXmlLocations">
    			<list>
    				<value>classpath*:META-INF/as400-daten/persistence.xml</value>
    				<value>classpath*:META-INF/postgresql/persistence.xml</value>
    				<!-- <value>classpath*:META-INF/persistence.xml</value> -->
    			</list>
    		</property>
    		<property name="dataSources">
    			<map>
    				<entry key="as400-daten" value-ref="DatenAs400Db2XaDataSource" />
    				<entry key="postgresql" value-ref="PostgreSqlXaDataSource" />
    			</map>
    		</property>
    		<!-- if no datasource is specified, use this one -->
    		<property name="defaultDataSource" ref="PostgreSqlXaDataSource" />
    	</bean>
    
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitManager" ref="pum" />
    		<property name="persistenceUnitName" value="as400-daten" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="false" />
    				<property name="generateDdl" value="false" />
    			</bean>
    		</property>
    		<!-- <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" 
    			/> </property> -->
    		<!-- <property name="jpaProperties"> <value> hibernate.cache.provider_class=net.sf.ehcache.hibernate.SingletonEhCacheProvider 
    			hibernate.cache.use_query_cache=true hibernate.cache.use_second_level_cache=true 
    			net.sf.ehcache.configurationResourceName=../config/ehcache.xml </value> </property> -->
    	</bean>
    
    	<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    		init-method="init" destroy-method="close">
    		<property name="forceShutdown">
    			<value>true</value>
    		</property>
    		<property name="startupTransactionService" value="true" />
    	</bean>
    
    	<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    		<property name="transactionTimeout">
    			<value>300</value>
    		</property>
    	</bean>
    
    	<bean id="transactionManager"
    		class="org.springframework.transaction.jta.JtaTransactionManager">
    		<property name="transactionManager">
    			<ref bean="atomikosTransactionManager" />
    		</property>
    		<property name="userTransaction">
    			<ref bean="atomikosUserTransaction" />
    		</property>
    	</bean>
    
    	<bean
    		class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    
    	<tx:annotation-driven transaction-manager="transactionManager" />
    
    	<context:component-scan base-package="at.vaeb"/>
    	<!-- Enable processing of @PersistenceContext and @PersistenceUnit -->
    	<context:annotation-config />
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
    </beans>
    /META-INF/as400-daten/persistence.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
    	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    
    	<persistence-unit name="as400-daten" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<properties>
    			<property name="default" value="false" />
    			<property name="hibernate.connection.url" value="" />
    			<property name="hibernate.connection.driver_class" value="com.ibm.as400.access.AS400JDBCDriver" />
    			<property name="hibernate.connection.password" value="****" />
    			<property name="hibernate.connection.username" value="****" />
    			<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
    			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
    		</properties>
    	</persistence-unit>
    
    </persistence>

  • #2
    continue.....

    /META-INF/postgresql/persistence.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
    	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    
    	<persistence-unit name="postgresql" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<!-- 
    		<class>xxx</class>
    		 -->
    		<properties>
    			<property name="default" value="true" />
    			<property name="hibernate.connection.url" value="jdbc:postgresql://10.xx.xxx.xx:5432/xyz" />
    			<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
    			<property name="hibernate.connection.password" value="****" />
    			<property name="hibernate.connection.username" value="****" />
    			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
    			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
    		</properties>
    	</persistence-unit>
    
    </persistence>
    UserDao
    Code:
    package at.vaeb.dls.dao;
    
    import at.vaeb.dls.model.pg.User;
    
    public interface UserDao extends BaseDao<User, String> {
        User getUser(String userId);
    
    	User createUser(String svnr);
    }
    UserDaoImpl
    Code:
    package at.vaeb.dls.dao.impl;
    
    import java.sql.Timestamp;
    import java.util.Calendar;
    import java.util.List;
    
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    
    import org.springframework.stereotype.Component;
    import org.springframework.stereotype.Repository;
    import org.springframework.transaction.annotation.Propagation;
    import org.springframework.transaction.annotation.Transactional;
    
    import at.vaeb.dls.dao.UserDao;
    import at.vaeb.dls.model.pg.User;
    
    @Component
    @Repository
    public class UserDaoImpl implements UserDao {
    
    	private EntityManager em;
    
    	@PersistenceContext(name = "postgresql")
    	void setEntityManager(EntityManager em) {
    		this.em = em;
    	}
    
    	@Override
    	public User getUser(String id) {
    		return (User) this.em.find(User.class, id);
    	}
    
    	@Override
    	public User createUser(String svnr) {
    		User user = new User();
    		user.setUsername(svnr);
    		user.setDateCreated(new Timestamp(Calendar.getInstance()
    				.getTimeInMillis()));
    		return user;
    	}
    
    	@Override
    	public void persist(User entity) {
    		Timestamp oldDateUpdated = entity.getDateUpdated();
    		try {
    			entity.setDateUpdated(new Timestamp(Calendar.getInstance()
    					.getTimeInMillis()));
    			if (this.em.contains(entity))
    				this.em.persist(entity);
    			else
    				this.em.merge(entity);
    			
    			// Here the TransactionRequiredException happens.
    			this.em.flush();
    			
    		} catch (Exception e) {
    			entity.setDateUpdated(oldDateUpdated);
    			throw new RuntimeException(e);
    		}
    	}
    
    	@Override
    	@SuppressWarnings("unchecked")
    	public List<User> findAll() {
    		return this.em.createQuery("select u from User u").getResultList();
    	}
    
    	@Override
    	public User findById(String id) {
    		return this.em.find(User.class, id);
    	}
    
    	@Override
    	public void delete(User entity) {
    		this.em.remove(entity);
    	}
    }
    SecurityService
    Code:
    package at.vaeb.dls.service;
    
    import at.vaeb.dls.model.pg.User;
    
    
    
    public interface SecurityService {
    
    	User createOnlineAppUser(String svnr) throws SecurityServiceException;
    
    	User getUser(String testSvnr);
    
    }
    SecurityServiceImpl
    Code:
    package at.vaeb.dls.service.impl;
    
    import java.util.HashSet;
    
    import javax.inject.Inject;
    import javax.inject.Named;
    import javax.inject.Singleton;
    
    import org.apache.log4j.Logger;
    import org.springframework.transaction.annotation.Propagation;
    import org.springframework.transaction.annotation.Transactional;
    
    import at.vaeb.dls.dao.AuthorityDao;
    import at.vaeb.dls.dao.UserDao;
    import at.vaeb.dls.model.pg.Authority;
    import at.vaeb.dls.model.pg.User;
    import at.vaeb.dls.service.SecurityService;
    
    @Named("securityService")
    @Singleton
    public class SecurityServiceImpl implements SecurityService {
    
    	private static final Logger log = Logger
    			.getLogger(SecurityServiceImpl.class);
    
    	@Inject
    	UserDao userDao;
    
    	@Inject
    	AuthorityDao authorityDao;
    
    	@Override
    	@Transactional(propagation=Propagation.REQUIRED)
    	public User createOnlineAppUser(String svnr) {
    
    		// TODO svnr check
    
    		// TODO snvr check gegen service?
    
    		Authority authority = authorityDao.createAuthority(svnr, "ROLE_USER");
    		User user = userDao.createUser(svnr);
    		user.setAuthorities(new HashSet<Authority>());
    		authority.setUser(user);
    		user.getAuthorities().add(authority);
    
    		generatePassword(user);
    
    		userDao.persist(user);
    		return user;
    	}
    
    	private void generatePassword(User user) {
    		// TODO generate password und verschlüssel es
    		user.setPassword("passwort");
    		user.setClearTextPassword("passwort");
    	}
    
    	@Override
    	@Transactional(propagation=Propagation.REQUIRED)
    	public User getUser(String testSvnr) {
    		User user = userDao.findById(testSvnr);
    		if (user == null) {
    			log.info("User with svnr '" + testSvnr + "' not found.");
    			return null;
    		}
    		StringBuilder sb = new StringBuilder();
    		for (Authority a : user.getAuthorities()) {
    			sb.append(a + ", ");
    		}
    		log.info("User " + user.getUsername() + " has following authorities: "
    				+ sb.toString());
    		return user;
    	}
    }
    SecurityServiceTest
    Code:
    package at.vaeb.dls.service;
    
    import javax.inject.Inject;
    
    import junit.framework.Assert;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import org.springframework.transaction.annotation.Transactional;
    
    import at.vaeb.dls.model.pg.User;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = "/service.spring.xml")
    public class SecurityServiceTest {
    
    	private static final String TEST_SVNR = "1234567890";
    	@Inject
    	SecurityService securityService;
    
    	@Test
    	public void dummyTest() {
    
    		try {
    			User origUser = securityService.createOnlineAppUser(TEST_SVNR);
    
    			User user = securityService.getUser(TEST_SVNR);
    
    			Assert.assertNotNull(user);
    			Assert.assertEquals(origUser.getUsername(), user.getUsername());
    
    		} catch (SecurityServiceException e) {
    			throw new RuntimeException(e);
    		}
    
    		System.out.println();
    	}
    }
    Last edited by mongole; Nov 4th, 2010, 10:17 AM. Reason: Mark the code line, where the exception occurs.

    Comment


    • #3
      third and last part

      the stack trace:
      Code:
      java.lang.RuntimeException: javax.persistence.TransactionRequiredException: no transaction is in progress
      	at at.vaeb.dls.dao.impl.UserDaoImpl.persist(UserDaoImpl.java:59)
      	at at.vaeb.dls.dao.impl.UserDaoImpl.persist(UserDaoImpl.java:1)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy37.persist(Unknown Source)
      	at at.vaeb.dls.service.impl.SecurityServiceImpl.createOnlineAppUser(SecurityServiceImpl.java:48)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy39.createOnlineAppUser(Unknown Source)
      	at at.vaeb.dls.service.SecurityServiceTest.dummyTest(SecurityServiceTest.java:26)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
      	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
      	at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:301)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
      	at $Proxy34.flush(Unknown Source)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
      	at $Proxy34.flush(Unknown Source)
      	at at.vaeb.dls.dao.impl.UserDaoImpl.persist(UserDaoImpl.java:55)
      	... 53 more
      If someone can give me a hint! I have no idea where to look now anymore

      Thanks in advance!

      greets,
      Andreas

      Comment


      • #4
        Possible solution?

        I've struggled with this for about a day, but I *think* I've managed to get it working by...

        1. Injecting the entityManager using @PersistenceContext rather than injecting the entityManagerFactory (using @PersistenceUnit).
        2. Defining my services in root-context.xml explicitly (i.e. not use @Service, @Component etc)

        I believe this is OK because spring is creating the entity manager via it's SharedEntityManagerCreater, making it thread safe.

        I've tried both @Transactional and <aop:config> for declaring the transaction boundaries, both worked OK.

        ** Update **

        I managed to get the @Service annotation working with @Transactional by setting proxy-target-class to true

        <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

        (See Table 10.2 in http://static.springsource.org/sprin...ansaction.html)
        Last edited by cressie176; Feb 27th, 2011, 10:15 AM.

        Comment


        • #5
          hello,

          I am facing the same problem, unfortunately your solution didn't work for me... is it maybe a bug ? when using xml for bean definition it works perfectly and when switching to @Repository or @Service annotation, the bean is detected and managed by Spring but the transactional behavior is deactivated

          Comment

          Working...
          X