deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodrigo <rcardo...@gmail.com>
Subject Re: i got a [A JTA EntityManager cannot use getTransaction] error
Date Sat, 28 Sep 2013 10:23:30 GMT
I had same error and including global alternatives at apache-deltaspike.properties solved this
problem.

Enviado via iPhone

Em 28/09/2013, às 04:02, Christian Kaltepoth <christian@kaltepoth.de> escreveu:

> BTW: Did you try the global-alternative approach mentioned in the JTA
> Support chapter of the documentation?
> 
> Just create a file called /META-INF/apache-deltaspike.properties on your
> classpath (in case of Maven it is
> src/main/resources/META-INF/apache-deltaspike.properties) and add the
> following content to the file:
> 
> globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
> 
> See:
> 
> http://deltaspike.apache.org/jpa.html#jta-support
> 
> Christian
> 
> 
> 
> 2013/9/28 Christian Kaltepoth <christian@kaltepoth.de>
> 
>> Could you include the full stacktrace?
>> 
>> Actually there should be no more ResourceLocalTransactionStrategy in the
>> stacktrace. Instead you should see BeanManagedUserTransactionStrategyinstead. At
least if your
>> <alternatives> configuration worked.
>> 
>> Which container do you deploy to?
>> 
>> Christian
>> 
>> 
>> 2013/9/28 十三郎 <mihaisheng@163.com>
>> 
>>> Christian Kaltepoth:thanks verymuch!!!!
>>> 
>>> 
>>> i add the alternatives section to beans.xml.
>>> 
>>> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
>>> http://www.w3.org/2001/XMLSchema-instance"
>>>    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>> http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
>>>    <interceptors>
>>> 
>>> <class>org.apache.deltaspike.security.impl.extension.SecurityInterceptor</class>
>>> 
>>> <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
>>>    </interceptors>
>>>    <alternatives>
>>> 
>>> <class>org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy</class>
>>>    </alternatives>
>>> </beans>
>>> 
>>> but the code still run to error(A JTA EntityManager cannot use
>>> getTransaction())
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> At 2013-09-27 16:52:29,"Christian Kaltepoth" <christian@kaltepoth.de>
>>> wrote:
>>>> Did you follow the instructions in the "JTA Support" section of the
>>>> documentation?
>>>> 
>>>> http://deltaspike.apache.org/jpa.html#jta-support
>>>> 
>>>> It looks like your are using the ResourceLocalTransactionStrategy instead
>>>> of BeanManagedUserTransactionStrategy which is required in case of JTA.
>>>> Adding the following section to your beans.xml should fix your problem:
>>>> 
>>>>   <alternatives>
>>>> 
>>> 
>>>> <class>org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy</class>
>>>>   </alternatives>
>>>> 
>>>> Best regards
>>>> 
>>>> Christian
>>>> 
>>>> 2013/9/27 十三郎 <mihaisheng@163.com>
>>>> 
>>>>> hi everyone:
>>>>> i defined a @Transactional method run to error.
>>>>> 
>>>>> follow deltaspike jpamodule documents,i define a EntityManagerProducer
>>>>> public class EntityManagerProducer
>>>>> {
>>>>>    @PersistenceContext(unitName = "persistence0")
>>>>>    private EntityManager entityManager;
>>>>>    @Produces
>>>>>    @RequestScoped
>>>>>    protected EntityManager createEntityManager()
>>>>>    {
>>>>>        return this.entityManager;
>>>>>    }
>>>>>    protected void closeEntityManager(@Disposes EntityManager
>>>>> entityManager)
>>>>>    {
>>>>>        if (entityManager.isOpen())
>>>>>        {
>>>>>            entityManager.close();
>>>>>        }
>>>>>    }
>>>>> }
>>>>> 
>>>>> 
>>>>> and i want do some database action:
>>>>> ---------------------------
>>>>> @Named("jpaTest")
>>>>> public class JpaTest
>>>>> {
>>>>>    @Inject
>>>>>    private EntityManager entityManager;
>>>>>    @Named
>>>>>    @Transactional
>>>>>    public void executeInTransaction(){
>>>>>        Query query = null;
>>>>>        String sql="insert into grandscape_user
>>> (user_name,user_password)
>>>>> values (:u,:p)";
>>>>>        query=entityManager.createNativeQuery(sql);
>>>>>        query.setParameter("u", "2013");
>>>>>        query.setParameter("p", "20132222");
>>>>>        query.executeUpdate();
>>>>>    }
>>>>> }
>>>>> -------------------
>>>>> 
>>>>> 
>>>>> i use jsf  to call method #{jpaTest.executeInTransaction}.
>>>>> <h:commandButton value="jpa Method"
>>>>> action="#{jpaTest.executeInTransaction}" />
>>>>> 
>>>>> and persistence.xml:
>>>>> ---------------------
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <persistence 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"
>>>>>    version="2.0">
>>>>>    <persistence-unit name="persistence0" transaction-type="JTA">
>>>>>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>>>>    <jta-data-source>java:jboss/datasources/MysqlDS</jta-data-source>
>>>>>        <properties>
>>>>>            <!-- Properties for Hibernate (default provider for JBoss
>>> AS)
>>>>> -->
>>>>>            <property name="hibernate.dialect"
>>>>> value="org.hibernate.dialect.MySQLDialect"/>
>>>>>               <property name="hibernate.connection.username"
>>> value="root"
>>>>> />
>>>>>                   <property name="hibernate.connection.password"
>>>>> value="root" />
>>>>>                   <property name="hibernate.connection.driver_class"
>>>>> value="com.mysql.jdbc.Driver" />
>>>>>                   <property name="hibernate.connection.url"
>>>>> value="jdbc:mysql://localhost:3306/grandscape_website" />
>>>>> 
>>>>>            <property name="hibernate.show_sql" value="true"/>
>>>>>            <!-- Only format when you need to debug, because it slows
>>>>> things down -->
>>>>>            <property name="hibernate.format_sql" value="false"/>
>>>>>            <property name="hibernate.show_sql" value="true" />
>>>>>            <property name="hibernate.hbm2ddl.auto" value="update"
/>
>>>>>            <!--
>>>>>            <property name="hibernate.hbm2ddl.auto"
>>> value="create-drop"/>
>>>>>            -->
>>>>>        </properties>
>>>>>    </persistence-unit>
>>>>> </persistence>
>>>>> ------------
>>>>> 
>>>>> 
>>>>> when i called #{jpaTest.executeInTransaction} method,the code run to
a
>>>>> error:
>>>>> ----------------------------------------
>>>>> 16:39:53,889 WARNING
>>>>> [javax.enterprise.resource.webcontainer.jsf.lifecycle]
>>>>> (http--0.0.0.0-8080-1) #{jpaTest.executeInTransaction}:
>>>>> java.lang.IllegalStateException: A JTA EntityManager cannot use
>>>>> getTransaction(): javax.faces.FacesException:
>>>>> #{jpaTest.executeInTransaction}: java.lang.IllegalStateException: A JTA
>>>>> EntityManager cannot use getTransaction()
>>>>>    at
>>>>> 
>>> com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    at
>>>>> javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    at
>>>>> 
>>> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    at
>>>>> 
>>> com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    at
>>>>> com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
>>>>> [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
>>>>>    at
>>>>> 
>>> org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
>>>>> [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]
>>>>> Caused by: javax.faces.el.EvaluationException:
>>>>> java.lang.IllegalStateException: A JTA EntityManager cannot use
>>>>> getTransaction()
>>>>>    at
>>>>> 
>>> javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    at
>>>>> 
>>> com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    ... 24 more
>>>>> Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot
>>> use
>>>>> getTransaction()
>>>>>    at
>>>>> 
>>> org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:996)
>>>>> [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
>>>>>    at
>>>>> 
>>> org.jboss.as.jpa.container.AbstractEntityManager.getTransaction(AbstractEntityManager.java:498)
>>>>> [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
>>>>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at java.lang.reflect.Method.invoke(Method.java:601)
>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:44)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> org.jboss.weld.proxies.EntityManager$-1071677489$Proxy$_$$_WeldClientProxy.getTransaction(EntityManager$-1071677489$Proxy$_$$_WeldClientProxy.java)
>>>>> [weld-core-1.1.5.AS71.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.getTransaction(ResourceLocalTransactionStrategy.java:265)
>>>>> [deltaspike-jpa-module-impl-0.4.jar:0.4]
>>>>>    at
>>>>> 
>>> org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:130)
>>>>> [deltaspike-jpa-module-impl-0.4.jar:0.4]
>>>>>    at
>>>>> 
>>> org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.executeInTransaction(TransactionalInterceptor.java:57)
>>>>> [deltaspike-jpa-module-impl-0.4.jar:0.4]
>>>>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at java.lang.reflect.Method.invoke(Method.java:601)
>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> org.jboss.interceptor.proxy.InterceptorInvocation$InterceptorMethodInvocation.invoke(InterceptorInvocation.java:72)
>>>>> [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final]
>>>>>    at
>>>>> 
>>> org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:82)
>>>>> [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final]
>>>>>    at
>>>>> 
>>> org.jboss.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:133)
>>>>> [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final]
>>>>>    at
>>>>> 
>>> org.jboss.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:112)
>>>>> [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final]
>>>>>    at
>>>>> 
>>> org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> org.jboss.weld.proxies.JpaTest$Proxy$_$$_WeldSubclass.executeInTransaction(JpaTest$Proxy$_$$_WeldSubclass.java)
>>>>> [weld-core-1.1.5.AS71.Final.jar:]
>>>>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at
>>>>> 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>> [rt.jar:1.7.0_07]
>>>>>    at java.lang.reflect.Method.invoke(Method.java:601)
>>> [rt.jar:1.7.0_07]
>>>>>    at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
>>>>> [jbossweb-7.0.13.Final.jar:]
>>>>>    at
>>>>> 
>>> org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
>>>>> [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
>>>>>    at
>>>>> 
>>> com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
>>>>> [jsf-impl-2.1.7-jbossorg-2.jar:]
>>>>>    at
>>>>> 
>>> javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
>>>>> [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
>>>>>    ... 25 more
>>>>> 
>>>>> 16:39:53,937 ERROR
>>>>> 
>>> [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/website_deltaspike].[FacesServlet]]
>>>>> (http--0.0.0.0-8080-1) Servlet.service() for serv

Mime
View raw message