You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Richard Grin <Ri...@univ-cotedazur.fr> on 2021/10/06 10:34:09 UTC

Insertion of the code for an EntityManager in a session bean is not good

Hello,

It's a regression but I don't remember in which version it worked (some 
years ago). It does not work in 12.4 nor in 12.5 (Windows 10).

The option "Insert code..." > "Use Entity Manager..." of the context 
menu of a session bean stateless does not insert the good code.

Even if the transactions are not managed by the EJB (the behaviour by 
default), it inserts this code (this code would be good if the 
transaction was managed by the EJB, i.e. in an EJB annotated by 
"@TransactionManagement(TransactionManagementType.BEAN)"):

   @PersistenceContext(unitName = "customerPU")
   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 insert this code:

   @PersistenceContext(unitName = "customerPU")
   private EntityManager em;

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

Example of the code of the EJB in which I try to insert the code :

@Stateless
public class Test {

}

Richard


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: Insertion of the code for an EntityManager in a session bean is not good

Posted by Gaurav Gupta <ga...@gmail.com>.
Hi Everyone,

I started working on https://issues.apache.org/jira/browse/NETBEANS-3270
ticket which seems related to it.

Thanks and kind regards,
Gaurav Gupta





On Wed, Oct 6, 2021 at 4:04 PM Richard Grin <Ri...@univ-cotedazur.fr>
wrote:

> Hello,
>
> It's a regression but I don't remember in which version it worked (some
> years ago). It does not work in 12.4 nor in 12.5 (Windows 10).
>
> The option "Insert code..." > "Use Entity Manager..." of the context
> menu of a session bean stateless does not insert the good code.
>
> Even if the transactions are not managed by the EJB (the behaviour by
> default), it inserts this code (this code would be good if the
> transaction was managed by the EJB, i.e. in an EJB annotated by
> "@TransactionManagement(TransactionManagementType.BEAN)"):
>
>    @PersistenceContext(unitName = "customerPU")
>    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 insert this code:
>
>    @PersistenceContext(unitName = "customerPU")
>    private EntityManager em;
>
>    public void persist(Object object) {
>      em.persist(object);
>    }
>
> Example of the code of the EJB in which I try to insert the code :
>
> @Stateless
> public class Test {
>
> }
>
> Richard
>
>