Return-Path: X-Original-To: apmail-deltaspike-users-archive@www.apache.org Delivered-To: apmail-deltaspike-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9CF6110E5C for ; Sat, 28 Sep 2013 07:47:27 +0000 (UTC) Received: (qmail 46743 invoked by uid 500); 28 Sep 2013 07:41:38 -0000 Delivered-To: apmail-deltaspike-users-archive@deltaspike.apache.org Received: (qmail 46686 invoked by uid 500); 28 Sep 2013 07:41:31 -0000 Mailing-List: contact users-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@deltaspike.apache.org Delivered-To: mailing list users@deltaspike.apache.org Received: (qmail 46664 invoked by uid 99); 28 Sep 2013 07:41:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Sep 2013 07:41:24 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of chkalt@gmail.com designates 209.85.215.51 as permitted sender) Received: from [209.85.215.51] (HELO mail-la0-f51.google.com) (209.85.215.51) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Sep 2013 07:41:20 +0000 Received: by mail-la0-f51.google.com with SMTP id es20so2956045lab.10 for ; Sat, 28 Sep 2013 00:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=AETtfSfQa373FlMSlDbvF5BxAydj5qNhTn3vN0ImfMc=; b=XUp0zYxPrAkukdSnA5hs8GEtBgIkaL64D/e4Up/YTtChl7Fw8x3SZ8oSdx6MGicYgk 8JBa5nRFE/IbxOpfXnot/BzC7F+Abui3NuY/nneiFFp9IVMkvguU6TEVYZb7vOK+J1Tx F9Ksg6jxWuNZnh80t7rzyRJaYEcKO4Ud8Jk8542jrSbWI0KZT5CgRuDJJEJyvQNKGv+o h7qxEP5TD2kMmcVjiJ11XCeLBXKO928/2A1Z3Eip8p2t4yOXe0gKDOifxcNKcURG8Pkl QxYb0kXyTZ9wCa8l0FPmbK5V0jrGBVGsxSGHfAHiUuExDcJo1vdTft+fzosgF4F0vcX1 J52Q== MIME-Version: 1.0 X-Received: by 10.152.88.74 with SMTP id be10mr9482741lab.4.1380354058735; Sat, 28 Sep 2013 00:40:58 -0700 (PDT) Sender: chkalt@gmail.com Received: by 10.112.99.171 with HTTP; Sat, 28 Sep 2013 00:40:58 -0700 (PDT) In-Reply-To: <81b019.147d1.14162cd6c33.Coremail.mihaisheng@163.com> References: <81b019.147d1.14162cd6c33.Coremail.mihaisheng@163.com> Date: Sat, 28 Sep 2013 09:40:58 +0200 X-Google-Sender-Auth: 18lgRsVNPwdIBW9F9TWrcCVgzok Message-ID: Subject: Re: i write a simple DS jpa demo,still hava two bugs. From: Christian Kaltepoth To: users@deltaspike.apache.org Content-Type: multipart/alternative; boundary=001a11c34e6c55d6b204e76cb9c2 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c34e6c55d6b204e76cb9c2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Regarding BUG2: AFAIK you can remove the closeEntityManager() method because the lifecycle of the EntityManager is managed by the container. I think our documentation may need some improvement regarding this. Christian 2013/9/28 =E5=8D=81=E4=B8=89=E9=83=8E > hi everyone: > i write a simple jpa demo,still hava two bugs. > (i use jboss as 7.1.1.final ; jdk1.7) > > 1,follow deltaspike jpamodule documents,i define a EntityManagerProducer > public class EntityManagerProducer > { > @PersistenceContext(unitName =3D "persistence0") > private EntityManager entityManager; > @Produces > @RequestScoped > protected EntityManager createEntityManager() > { > return this.entityManager; > } > protected void closeEntityManager(@Disposes EntityManager > entityManager) > { > if (entityManager.isOpen()) > { > entityManager.close(); > } > } > } > > > 2,and i want do some database action: > --------------------------- > @Named("jpaTest") > public class JpaTest > { > @Inject > private EntityManager entityManager; > @Named > @Transactional > public void executeInTransaction(){ > Query query =3D null; > String sql=3D"insert into grandscape_user (user_name,user_passwor= d) > values (:u,:p)"; > query=3DentityManager.createNativeQuery(sql); > query.setParameter("u", "2013"); > query.setParameter("p", "20132222"); > query.executeUpdate(); > } > } > ------------------- > > > 3,i use jsf to call method #{jpaTest.executeInTransaction}. > action=3D"#{jpaTest.executeInTransaction}" /> > > 4,and persistence.xml. > if transaction-type=3D"JTA" ,the code run to [A JTA EntityManager cannot = use > getTransaction] error. > > (BUG1) > i add the alternatives section to beans.xml to fix. > http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=3D"http://java.sun.com/xml/ns/javaee > http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> > > > org.apache.deltaspike.security.impl.extension.SecurityInterceptor<= /class> > > org.apache.deltaspike.jpa.impl.transaction.TransactionalIntercepto= r > > > > org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransac= tionStrategy > > > but the code still run to error(A JTA EntityManager cannot use > getTransaction()) > so i set transaction-type=3D"RESOURCE_LOCAL". > --------------------- > > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=3D"http://java.sun.com/xml/ns/persistence > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" > version=3D"2.0"> > transaction-type=3D"RESOURCE_LOCAL"> > org.hibernate.ejb.HibernatePersistence > java:jboss/datasources/MysqlDS > > > value=3D"org.hibernate.dialect.MySQLDialect"/> > /> > value=3D"root" /> > value=3D"com.mysql.jdbc.Driver" /> > value=3D"jdbc:mysql://localhost:3306/grandscape_website" /> > > > > > > > > > > > ------------ > > > 5,finally,when i called #{jpaTest.executeInTransaction} method,the data > was fill to database successful, > but the code run to a error: > > (BUG2) > -------------------------- > > ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]] > (http--0.0.0.0-8080-1) Exception sending request destroyed lifecycle even= t > to listener instance of class org.jboss.weld.servlet.WeldListener: > java.lang.IllegalStateException: JBAS011424: Container managed entity > manager can only be closed by the container (auto-cleared at tx/invocatio= n > end and closed when owning component is closed.) > at > org.jboss.as.jpa.container.TransactionScopedEntityManager.close(Transacti= onScopedEntityManager.java:98) > [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final] > at > persist.EntityManagerProducer.closeEntityManager(EntityManagerProducer.ja= va:21) > [classes:] > 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(DelegatingMethodAccessorI= mpl.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.util.reflection.SecureReflections$13.work(SecureReflection= s.java:264) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectio= nAccess.java:52) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(Sec= ureReflectionAccess.java:137) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections= .java:260) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMetho= dImpl.java:170) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(Forward= ingWeldMethod.java:51) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecial= Value(MethodInjectionPoint.java:154) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.bean.DisposalMethod.invokeDisposeMethod(DisposalMethod.jav= a:158) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.bean.ProducerMethod$1.dispose(ProducerMethod.java:122) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at org.jboss.weld.bean.ProducerMethod.destroy(ProducerMethod.java:197= ) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.ForwardingContextual.destroy(ForwardingContextual.= java:31) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.AbstractContext.destroy(AbstractContext.java:132) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.AbstractContext.destroy(AbstractContext.java:146) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.AbstractManagedContext.deactivate(AbstractManagedC= ontext.java:41) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundConte= xt.java:72) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequest= ContextImpl.java:86) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:10= 3) > [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:= 185) > [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.j= ava:109) > [jbossweb-7.0.13.Final.jar:] > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:36= 8) > [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(H= ttp11Protocol.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] > --------------------------------- > > if i delete [entityManager.close();] line in EntityManagerProducer,the > error disappeared. --=20 Christian Kaltepoth Blog: http://blog.kaltepoth.de/ Twitter: http://twitter.com/chkal GitHub: https://github.com/chkal --001a11c34e6c55d6b204e76cb9c2--