From users-return-3573-apmail-netbeans-users-archive=netbeans.apache.org@netbeans.apache.org Thu Aug 1 14:40:03 2019 Return-Path: X-Original-To: apmail-netbeans-users-archive@minotaur.apache.org Delivered-To: apmail-netbeans-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id AC1F61944B for ; Thu, 1 Aug 2019 14:40:03 +0000 (UTC) Received: (qmail 81702 invoked by uid 500); 1 Aug 2019 14:39:58 -0000 Delivered-To: apmail-netbeans-users-archive@netbeans.apache.org Received: (qmail 81630 invoked by uid 500); 1 Aug 2019 14:39:58 -0000 Mailing-List: contact users-help@netbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@netbeans.apache.org Received: (qmail 81620 invoked by uid 99); 1 Aug 2019 14:39:58 -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; Thu, 01 Aug 2019 14:39:58 +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 0050B182844 for ; Thu, 1 Aug 2019 14:39:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.051 X-Spam-Level: ** X-Spam-Status: No, score=2.051 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com 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 QEuKIfzOx2Go for ; Thu, 1 Aug 2019 14:39:54 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.167.46; helo=mail-lf1-f46.google.com; envelope-from=javier.ortiz.78@gmail.com; receiver= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id F0B14BC7F3 for ; Thu, 1 Aug 2019 14:39:53 +0000 (UTC) Received: by mail-lf1-f46.google.com with SMTP id r15so33449545lfm.11 for ; Thu, 01 Aug 2019 07:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6oEJXIk1fNz/udpxge4cRsxHBOX2slHtQ9O94klfliA=; b=NvsMFFB6Ki0uUb50ZILHoSfQgwXNJr0w6+GSPUJU5SWHcba7Hj+Aam5XZ0+LhMFIHE Fz0JXp5nO0xbdsosv5vem8pZJpaZMX42YELdU+oLsXrLxcipsgY5xev8S9/njXTkHKpq bn/WOo03tUuSYuJG3S0MJbmTJr/SEA0zdyLYLWk60pM9I6MGmKQTSCakuDBZVpIjs2Yq zhd8/Q+K7S5K62riHbDWBHQ1jDGlVkQOviISlgPgTN8Od8IYR+lEUfPvft2wMMoBvUDn XSBc0mleOs84P839BZ0tsnE8uzm4jqfllOD+Q8aFk6AmIqtP6EoJJ0dTBoL62q2E1oC6 lt7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6oEJXIk1fNz/udpxge4cRsxHBOX2slHtQ9O94klfliA=; b=hUnUM1sxjHhxyl1qVkXa+RsTh/j01AmuGfm+NsWkfNaFUd4dQeXNoSZzjH8tGEcr3W OyXE0MR/SLdri5vMCRyN/8CE/RJ3JZOft/jGYwnkt07SIh9SwZW0tx/yRlP5EZZiS85O 6Zy4qjH5DvXKw4NHoq7BiZQOm6Ngb9Q9sD2IgY0TkSV2FWmtD0O2AhV906hLD2WbktHy KMULEijtviwcCkY14khd5e07el/H6345rli4jeE9XpZh0tTAEslAWU9xL9hHm8hhAV/6 kuyhquOd7Dp2hwvPeZLeXzZF6zsdHm8yNo9hGzGUaheGcHQORKkKttg7xkTUDr0+RJBy cXtg== X-Gm-Message-State: APjAAAX4R25muOh7uK0JvEzftB5OcgtS70vZUJ7Av3ep4nxaWBsFxF1s m9cWeIvXIfDmYvUX+KFxIAerHZuKwvKcopFu5+I= X-Google-Smtp-Source: APXvYqxsltze9DTishVgqV03Q13IS30rzms1C6/3RqIq9rTHooXzQy5CkHNA0YkbcvM+HULS+U5ZA86l0PnpHfDMiSc= X-Received: by 2002:ac2:5609:: with SMTP id v9mr58831484lfd.27.1564670387077; Thu, 01 Aug 2019 07:39:47 -0700 (PDT) MIME-Version: 1.0 References: <7e1a9cb7-bc09-ec86-9418-3752bacf259c@univ-cotedazur.fr> In-Reply-To: <7e1a9cb7-bc09-ec86-9418-3752bacf259c@univ-cotedazur.fr> From: Javier Ortiz Date: Thu, 1 Aug 2019 09:39:34 -0500 Message-ID: Subject: Re: Injection of an EntityManager is not adapted to CMT mode To: Richard Grin Cc: users@netbeans.apache.org Content-Type: multipart/alternative; boundary="0000000000009cc8a8058f0f3602" --0000000000009cc8a8058f0f3602 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Yes, please do. https://issues.apache.org/jira/projects/NETBEANS/issues/NETBEANS-2931?filte= r=3Dallopenissues On Thu, Aug 1, 2019, 9:29 AM Richard Grin wrote: > Do I have to report this problem elsewhere for it to have a chance to be > fixed? > > I found other problems in other codes generated by NetBeans and I prefer > to report them the right way. > > Regards, > > Richard > Le 29/07/2019 =C3=A0 16:06, Richard Grin a =C3=A9crit : > > Hi Ortiz, > > The EJB in which I inject is NOT annotated by > > @TransactionManagement( TransactionManagementType.BEAN) > > so, by default, the transactions are managed by the container: one > automatic commit or rollback at the end of the method which started the > transaction (I won't go into the details... ; see > https://javaee.github.io/tutorial/transactions004.html#BNCIJ). A > UserTransaction must not be used. The old versions of NetBeans inserted t= he > good code. > > See the code of Arjan Tijms in > https://stackoverflow.com/questions/8772175/how-to-implement-container-ma= naged-transaction-cmt > . > > Regards, > > Richard > Le 29/07/2019 =C3=A0 13:33, Javier Ortiz a =C3=A9crit : > > The current one seems completely correct to me. What error/problem are yo= u > getting? > > That's an atomic operation. > > On Mon, Jul 29, 2019, 5:31 AM Richard Grin > wrote: > >> Hi, >> >> NetBeans 11.1. >> >> The code generated by NetBeans for the injection of an EntityManager is >> not adapted to the CMT (Container Managed Transaction) mode. "Generate" >> menu for "Insert code..." > "Use Entity Manager...". >> >> The generated code: >> >> @PersistenceContext(unitName =3D "xxx") >> private EntityManager em; >> @Resource >> private javax.transaction.UserTransaction utx; >> >> public void persist(Object object) { >> try { >> utx.begin(); >> em.persist(object); >> utx.commit(); >> } catch (Exception e) { >> Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception >> caught", e); >> throw new RuntimeException(e); >> } >> } >> >> It should be >> >> @PersistenceContext(unitName =3D xxx") >> private EntityManager em; >> >> public void persist(Object object) { >> em.persist(object); >> } >> >> Richard >> >> -- > Cordialement, > > Richard Grin > > -- > Cordialement, > > Richard Grin > > --0000000000009cc8a8058f0f3602 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Aug 1, 2019, 9:29 AM Richard Grin <Richard.GRIN@univ-cotedazur.fr>= wrote:

Do I have to report this problem elsewhere for it to have a chance to be= fixed?

I found other problems in other codes generated by NetBeans and I prefer= to report them the right way.

Regards,

Richard

Le 29/07/2019 =C3=A0 16:= 06, Richard Grin a =C3=A9crit=C2=A0:

Hi Ortiz,

The EJB in which I inject is NOT annotated by

@TransactionManagement( TransactionManagementType.BEAN)

so, by default, the transactions are managed by the container: one autom= atic commit or rollback at the end of the method which started the transact= ion (I won't go into the details... ; see https://javaee.github.io/tutorial/transactions004.html#BNCIJ). A UserTr= ansaction must not be used. The old versions of NetBeans inserted the good = code.

See the code of Arjan Tijms in https://stackoverflow.com/questions/8772175/how-to-implement-container-mana= ged-transaction-cmt.

Regards,

Richard

Le 29/07/2019 =C3=A0 13:= 33, Javier Ortiz a =C3=A9crit=C2=A0:
The current one seems completely correct to me. What erro= r/problem are you getting?

That's an atomic operation.=C2=A0

On Mon, Jul 29, 2019, 5:31 AM Richard= Grin <Richard.GRIN@univ-cotedazur.fr> wrote:
Hi,

NetBeans 11.1.

The code generated by NetBeans for the injection of an EntityManager is not adapted to the CMT (Container Managed Transaction) mode. "Generate= "
menu for "Insert code..." > "Use Entity Manager...".=

The generated code:

=C2=A0=C2=A0=C2=A0=C2=A0 @PersistenceContext(unitName =3D "xxx")<= br> =C2=A0=C2=A0=C2=A0=C2=A0 private EntityManager em;
=C2=A0=C2=A0=C2=A0=C2=A0 @Resource
=C2=A0=C2=A0=C2=A0=C2=A0 private javax.transaction.UserTransaction utx;

=C2=A0=C2=A0=C2=A0=C2=A0 public void persist(Object object) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ut= x.begin();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 em= .persist(object);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ut= x.commit();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 th= row new RuntimeException(e);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0 }

It should be

=C2=A0=C2=A0=C2=A0=C2=A0 @PersistenceContext(unitName =3D xxx")
=C2=A0=C2=A0=C2=A0=C2=A0 private EntityManager em;

=C2=A0=C2=A0=C2=A0=C2=A0 public void persist(Object object) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 em.persist(object);
=C2=A0=C2=A0=C2=A0=C2=A0 }

Richard

--=20
Cordialement,

Richard Grin
--=20
Cordialement,

Richard Grin
--0000000000009cc8a8058f0f3602--