Announcement Announcement Module
Collapse
No announcement yet.
JPA, JTA, EJB & glassfish V2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA, JTA, EJB & glassfish V2

    hi !

    I'm new to Spring and i'm facing an issue.

    I want to create a DAO layer in my application between EJB (v3) and database.
    Im' trying to inject my DAO object into my EJB (and inject persistenceContext in my DAO).

    I make working the DAO and the persistenceContext injection ( i use EJB interceptor and autowired)
    but when i try to use the injected entityManager i have an Exception:

    Code:
    Caused by: javax.persistence.TransactionRequiredException:
    Exception Description: No transaction is currently active
            at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionWrapper.throwCheckTransactionFailedException(EntityTransactionWrapper.java:85)
            at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:77)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:674)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.flush(EntityManagerImpl.java:366)
            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:358)
            at $Proxy935.flush(Unknown Source)
            at fr.plop.PlopDAOImpl.flush(PlopDAOImpl.java:44)
            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:307)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
            at $Proxy932.flush(Unknown Source)
            at fr.plop.PlopService.persist(PlopService.java:51)
            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 com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:181)
            at java.security.AccessController.doPrivileged(Native Method)
            at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:985)
            at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:186)
            at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4030)
            at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
            at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:205)
            at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4003)
            at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
            ... 17 more
    here is my application context:
    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:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
    		>
    
    	<tx:annotation-driven />
    	<context:annotation-config />
    	<context:component-scan base-package="fr.plop" />
    
    
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="seres" />
    	</bean>
    
    
    
    	<bean
    		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    		
    		
    
    	<bean id="transactionManager"
    		class="org.springframework.transaction.jta.JtaTransactionManager">
    	</bean>
    
    
    
    
    </beans>
    my DAO impl:
    Code:
    @Repository
    @Transactional(propagation=Propagation.REQUIRED)
    public class PlopDAOImpl implements PlopDAO {
    
    	private EntityManagerFactory emf;
    
        @PersistenceUnit
        public void setEntityManagerFactory(EntityManagerFactory emf) {
            this.emf = emf;
        }
    and my EJB
    Code:
    @Stateless(name = "PlopServiceBean")
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    @Service
    public class PlopService implements PlopServiceRemote {
    i tried a lot of thing, anybody can help me ?

    thanks a lot.

    plateform:
    Spring 2.5.6
    Glassfish v2.1
    JDK 1.6
    EJB v3
    Eclipse
    Last edited by kirinux; Jul 16th, 2009, 12:49 PM.
Working...
X