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 90031 - JSF pages from entities generates invalid code
Summary: JSF pages from entities generates invalid code
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSF (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Petr Pisl
URL:
Keywords:
: 104301 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-11-24 17:06 UTC by Erno Mononen
Modified: 2008-11-03 11:37 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
proposed patch (3.33 KB, text/plain)
2006-12-08 10:50 UTC, Erno Mononen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erno Mononen 2006-11-24 17:06:36 UTC
The JSF Pages from Entity Classes wizard generates code that is not in 
accordance with the usage of the Java Persistence API. More specifically, 
application-managed persistence context are not properly synchronized with JTA 
transactions. This causes for example silent failures when inserting data.

Steps:
1. Create a new wep application on SJSAS/GF
2. Create an entity class and a persistence unit using JTA
3. Create JSF pages from the entity => in the created controller class the 
following code is generated:

    public String create() {
        EntityManager em = getEntityManager();
        try {
            utx.begin();
            em.persist(entity);
            utx.commit();
    ....

The problem with this is that the entity manager is created outside of the 
active transaction scope and therefore it is not synchronized with the 
transaction. Because of this the persistence context is not flushed before the 
transaction commits and hence nothing is inserted into the database.

This can be fixed either by creating the entity manager within the transaction 
scope or by invoking em.joinTransaction() inside the scope.
Comment 1 Erno Mononen 2006-12-08 10:50:25 UTC
Created attachment 36575 [details]
proposed patch
Comment 2 Erno Mononen 2006-12-08 10:52:20 UTC
Attached is a patch for this issue. The patch adds a call to em.
joinTransaction() after the user transaction has started.
Comment 3 Petr Pisl 2006-12-08 12:09:02 UTC
The fix is ok for me. 
Comment 5 Jaroslav Pospisil 2006-12-20 14:04:12 UTC
Verified in 5.5 continuous build1220-1213.
Comment 6 Erno Mononen 2006-12-20 14:17:02 UTC
Reverted the previous commit in release55 branch.

http://web.netbeans.org/source/browse/web/jsf/src/org/netbeans/modules/web/jsf/wizards/JSFClinetGenerator.java?r1=1.1.2.48&r2=1.1.2.49

The patch in desc2 contains a typo, the actual patch that was verified in
release55 branch is the one linked from desc5.
Comment 7 Jaroslav Pospisil 2006-12-20 16:32:30 UTC
Verified in 5.5 continuous build1220-1213.
Comment 8 Erno Mononen 2006-12-22 12:30:41 UTC
Fixed in release551 branch.

Checking in JSFClinetGenerator.java;
/cvs/web/jsf/src/org/netbeans/modules/web/jsf/wizards/
JSFClinetGenerator.java,v  <--  JSFClinetGenerator.java
new revision: 1.1.2.47.8.1; previous revision: 1.1.2.47
done
Comment 9 Erno Mononen 2007-05-22 09:18:54 UTC
*** Issue 104301 has been marked as a duplicate of this issue. ***
Comment 10 martin_zmrhal 2008-11-03 11:37:41 UTC
verified

Product Version: NetBeans IDE Dev (Build 200811011401)
Java: 1.6.0_10-rc2; Java HotSpot(TM) Client VM 11.0-b15
System: Linux version 2.6.24-21-generic running on i386; UTF-8; en_US (nb)