This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 225043 - Complex code generation for "Use Entity Manager"
Summary: Complex code generation for "Use Entity Manager"
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.4
Hardware: PC All
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-17 23:50 UTC by arungupta
Modified: 2016-07-07 08:53 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description arungupta 2013-01-17 23:50:21 UTC
"Use Entity Manager" context-sensitive menu in an EJB

converts:

@Stateless
public class EmployeeBean {

}

TO

@Stateless
@PersistenceContext(name = "persistence/LogicalName", unitName = "org.sample_schema-gen_war_1.0-SNAPSHOTPU")
public class EmployeeBean {
    @Resource
    private javax.transaction.UserTransaction utx;

    protected void persist(Object object) {
        try {
            Context ctx = (Context) new InitialContext().lookup("java:comp/env");
            utx.begin();
            EntityManager em = (EntityManager) ctx.lookup("persistence/LogicalName");
            em.persist(object);
            utx.commit();
        } catch (Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
            throw new RuntimeException(e);
        }
    }
}

where as the simplified code can be:

@Stateless
public class EmployeeBean {

    @PersistenceContext
    EntityManager em;
    
    protected void persist(Object object) {
        em.persist(object);
    }
}
Comment 1 Sergey Petrov 2013-01-20 20:52:09 UTC
What 'dev' build is used?
Looks similar to http://netbeans.org/bugzilla/show_bug.cgi?id=195993
is it maven project?
Comment 2 arungupta 2013-01-22 18:31:52 UTC
7.2 with Maven is used.

Yes, it seems similar to http://netbeans.org/bugzilla/show_bug.cgi?id=195993.
Comment 3 Martin Balin 2016-07-07 08:53:46 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss