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 195993 - use entity manager code is inconsistent between ant and maven projects
Summary: use entity manager code is inconsistent between ant and maven projects
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.0
Hardware: PC All
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-25 12:17 UTC by Kenneth Ganfield
Modified: 2012-11-10 03:28 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Ganfield 2011-02-25 12:17:15 UTC
Product Version: NetBeans IDE Dev (Build 201102240001)
Java: 1.6.0_22; Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
System: Mac OS X version 10.5.8 running on x86_64; MacRoman; en_US (nb)
Userdir: /Applications/NetBeans/userdirs/7.0-20110222

The code generated by Use Entity Manager in a session bean is inconsistent between Ant and Maven projects. For more details, see issue 185682.

When you use the Use Entity Manager to generate code in an Ant project, the IDE generates the following:

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

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

When you use the same wizard in a Maven project, the code generated by the IDE is different:

@PersistenceContext(name = "persistence/LogicalName", unitName = "com.mycompany_mavenwebapp2_war_1.0-SNAPSHOTPU")
public class NewSessionBean {
    @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);
        }
    }
Comment 1 Sergey Petrov 2011-02-25 12:20:19 UTC
Is server set in maven project?
Comment 2 Kenneth Ganfield 2011-02-25 12:22:40 UTC
yes, GF 3.1 b43
Comment 3 Sergey Petrov 2011-03-01 17:22:45 UTC
both kind of code works for me with eclipselink 2.x, so can wait to fix.
also may have to test how it works with jpa1.0 and ee5 or lower.
Comment 4 Sergey Petrov 2012-08-15 12:51:47 UTC
unfortunately missed from 7.2 target, set to TBD to review in 7.3 timeframe
Comment 5 Sergey Petrov 2012-11-09 08:09:59 UTC
now maven should match to ant but it may need some additional testing
http://hg.netbeans.org/web-main/rev/fb8e2f591dd7
Comment 6 Quality Engineering 2012-11-10 03:28:11 UTC
Integrated into 'main-golden', will be available in build *201211100001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/fb8e2f591dd7
User: Sergey B. Petrov <sj-nb@netbeans.org>
Log: #195993 maven use the same generator now as in ant web project