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 247507 - generate jsf from entity classes uses incorrect annotations and incorrectly modifies pom
Summary: generate jsf from entity classes uses incorrect annotations and incorrectly m...
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 8.1
Hardware: Macintosh (x86) Mac OS X
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-26 21:44 UTC by jan.cetkovsky
Modified: 2014-10-03 21:57 UTC (History)
0 users

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 jan.cetkovsky 2014-09-26 21:44:54 UTC
When using the JSF Pages from entity classes, there is couple of problems:

*it uses @PersistenceContext instead of @PersistenceUnit if persistence.xml has transaction-type="RESOURCE_LOCAL" (generated by another NetBeans wizard), which is invalid, @PersistenceContext works only with transaction-type="JTA"
http://tomee.apache.org/jpa-concepts.html

*it adds the jpa dependency to pom even if its already there (provided)
(similar to https://netbeans.org/bugzilla/show_bug.cgi?id=247506) only the JSF wizard added 
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.2</version>
        </dependency>

even when JPA 2.0 provider using eclipselink-2.4.2 was used
Comment 1 Martin Fousek 2014-10-03 06:23:06 UTC
Thanks for reporting.

The persistence is generated by other (Persistence) area, so I'm reassigning the issue.
Comment 2 Sergey Petrov 2014-10-03 07:39:19 UTC
in general there is no support for libraries or for multiple libraries for the same jpa version, persistence support looks for first suitable library nb may know about. if some library is added manually and it's differnt version it may be hard for nb to understand if it's suitable enough.
Comment 3 jan.cetkovsky 2014-10-03 17:15:45 UTC
Sergey,

my opinion on that case is if there is a JPA provider already on classpath of the project, netbeans should not add another dependency to pom (not to mention it's adding JPA 2.1 dependency to project associated with JEE 6 server).

(and there is still the issue that the generated code is not correct for given persistence.xml)
Comment 4 Sergey Petrov 2014-10-03 20:27:08 UTC
for ant project this check may work as a solution, but I'm not sure regarding maven, what will happens in case if dependency isn't downloaded yet.
Comment 5 jan.cetkovsky 2014-10-03 20:37:57 UTC
maybe some configuration option than? I find NetBeans editing my pom incorrectly very annoying (and I would prefer it wouldn't touch it at all, if it's the only other option; it's not just this case - it seems as pretty typical use case to me that the JEE artifacts are in scope provided; they're part of the server - and I noticed multiple cases where netbeans adds something to pom that results in startup failure due to various classloading conflicts)
Comment 6 Sergey Petrov 2014-10-03 21:02:15 UTC
in general eclipselink shouldn't be added if server is registered, and it works this way for ant projects, eclipselink is added to processors classpath only. for maven separate processor classpath dependency isn't supported as I see the issue, or nb can't handle this case.
Comment 7 jan.cetkovsky 2014-10-03 21:34:27 UTC
Agree, but it should respect the pom on top of that - Imagine that I don't use the server integration of the IDE - just do the maven build and deploy it to my server manually - the pom is perfectly correct, yet netbeans would (incorrectly) change it only because I'm not using the integration feature? 

I haven't used ant in years - but I'd say the processors classpath is there because dependency management in ant is non existent. Using the dependency scopes properly should be equivalent in the maven world.
Comment 8 jan.cetkovsky 2014-10-03 21:49:11 UTC
This discussion should rather be under https://netbeans.org/bugzilla/show_bug.cgi?id=247506

the issue in this ticket was mainly about the fact that the generated Stateless *Facade beans does not respect the persistence.xml

(example below is generated from the sample MySQL employees db)

@Stateless
public class DepartmentsFacade extends AbstractFacade<Departments> {
    @PersistenceContext(unitName = "com.example_tutorial-jsf_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DepartmentsFacade() {
        super(Departments.class);
    }

}

with persistence.xml:
...
 <persistence-unit name="com.example_tutorial-jsf_war_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
...

the generated code should look like this to work:

@Stateless
public class DepartmentsFacade extends AbstractFacade<Departments> {
    @PersistenceUnit(unitName = "com.example_tutorial-jsf_war_1.0-SNAPSHOTPU")
    private EntityManagerFactory factory;

    @Override
    protected EntityManager getEntityManager() {
        return factory.createEntityManager();
    }

    public DepartmentsFacade() {
        super(Departments.class);
    }

}
Comment 9 jan.cetkovsky 2014-10-03 21:57:07 UTC
the code I added is not complete modification, it should either hold one instance of the EntityManager. The code I posted works, but will create multiple EntityManagers (if the current AbstractFacade is kept) which wouldn't be a good idea.