From users-return-2336-archive-asf-public=cust-asf.ponee.io@deltaspike.apache.org Mon May 4 20:24:16 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 859CF180608 for ; Mon, 4 May 2020 22:24:16 +0200 (CEST) Received: (qmail 15254 invoked by uid 500); 4 May 2020 20:24:15 -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 15240 invoked by uid 99); 4 May 2020 20:24:13 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 May 2020 20:24:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 40F15180F8C for ; Mon, 4 May 2020 20:24:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.211 X-Spam-Level: X-Spam-Status: No, score=0.211 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=0.2, KAM_DMARC_STATUS=0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-ec2-va.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 9jxcLIzNQ0Ym for ; Mon, 4 May 2020 20:24:09 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=81.196.173.39; helo=erelay.indsoft.ro; envelope-from=lucian.brancovean@indsoft.ro; receiver= Received: from erelay.indsoft.ro (erelay.indsoft.ro [81.196.173.39]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 47277BB85A for ; Mon, 4 May 2020 20:24:08 +0000 (UTC) Received: from SRV-EXC01.indsoft.local (192.168.123.38) by srv-exc01.indsoft.local (192.168.123.38) with Microsoft SMTP Server (TLS) id 15.1.466.34; Mon, 4 May 2020 23:24:04 +0300 Received: from SRV-EXC01.indsoft.local ([192.168.123.38]) by SRV-EXC01.indsoft.local ([192.168.123.38]) with mapi id 15.01.0466.037; Mon, 4 May 2020 23:24:04 +0300 From: Lucian BRANCOVEAN To: "users@deltaspike.apache.org" Subject: TransactionRequiredException when a transaction should exist Thread-Topic: TransactionRequiredException when a transaction should exist Thread-Index: AQHWIlG/TL3SIpkjdESS1GUp9aGCjA== Date: Mon, 4 May 2020 20:24:04 +0000 Message-ID: <763e38f950994fdfba5008206745db14@indsoft.ro> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [5.15.127.216] Content-Type: multipart/alternative; boundary="_000_763e38f950994fdfba5008206745db14indsoftro_" MIME-Version: 1.0 --_000_763e38f950994fdfba5008206745db14indsoftro_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I am using Deltaspike 1.9.3 in Wildfly 14. I have a CDI bean with a method that is supposed to insert or update an ent= ity, like this: @Named @ApplicationScoped public class StuffService { @Inject private StuffRepository repository; // StuffRepository extends EntityRe= pository ... @Transactional public void save(Stuff stuff) throws Exception { if (stuff.getCode() =3D=3D null) { repository.save(stuff); } else { Stuff entity =3D getByCode(stuff.getCode()); // code is @Id entity.setName(stuff.getName()); repository.save(entity); } } This works, but looking at the EntityRepository.save javadoc, I understand = that it already does what I want, decide if to update or insert a new recor= d based on the presence/absence of a primary key value. However, if I call repository.save() on an existing entity (so I remove the= if and always go in the first branch), I get an exception: javax.persistence.TransactionRequiredException: WFLYJPA0060: Transaction is= required to perform this operation (either use a transaction or extended p= ersistence context) at org.jboss.as.jpa@14.0.1.Final//org.jboss.as.jpa.container.AbstractEn= tityManager.transactionIsRequired(AbstractEntityManager.java:877) at org.jboss.as.jpa@14.0.1.Final//org.jboss.as.jpa.container.AbstractEn= tityManager.merge(AbstractEntityManager.java:564) What happens here? How come a transaction does not exist unless I create a = new object and transfer the data into it? What I guess might be relevant is that the Stuff entity comes from a ViewSc= oped bean, from a previous request. Note, I am using container-managed transactions, and javax.transaction.Tran= sactional. Should I use org.apache.deltaspike.jpa.api.transaction.Transacti= onal? What is the difference? Thanks in advance, Lucian --_000_763e38f950994fdfba5008206745db14indsoftro_--