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

2021-10-07 Thread Gaurav Gupta
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 
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
>
>


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

2021-10-06 Thread Richard Grin

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-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

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