Richard Grin created NETBEANS-2934:
--------------------------------------

             Summary:  Code generated to inject an EntityManager is not adapted 
to CMT mode
                 Key: NETBEANS-2934
                 URL: https://issues.apache.org/jira/browse/NETBEANS-2934
             Project: NetBeans
          Issue Type: Bug
    Affects Versions: 11.1
         Environment: Windows 10, NetBeans 11.1
            Reporter: Richard Grin


Alt-Insert to inject an EntityManager in an EJB is not good when the EJB is CMT.

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: 
{noformat}
    @PersistenceContext(unitName = "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);
         }
     }
{noformat}
It should be

 
{noformat}
@PersistenceContext(unitName = xxx")
 private EntityManager em;
public void persist(Object object) { em.persist(object); }
{noformat}
 
The generated code was good in NetBeans 9; I did not try with NetBeans 10.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

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

Reply via email to