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 219565 - Entity classes generated in ejb project can not be found in glashfish 3.1.2
Summary: Entity classes generated in ejb project can not be found in glashfish 3.1.2
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSF (show other bugs)
Version: 7.2
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Martin Fousek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-05 03:06 UTC by TianQing
Modified: 2012-10-23 12:10 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
this is full log of my glashfish (23.36 KB, text/plain)
2012-10-05 03:06 UTC, TianQing
Details
preview of the patch (6.64 KB, patch)
2012-10-12 08:09 UTC, Martin Fousek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description TianQing 2012-10-05 03:06:56 UTC
Created attachment 125421 [details]
this is full log of my glashfish

Hi,

I created a Enterprise application with two projects ebj and web.
Then I generate Entity Class from DB in ebj project, it's ok.
Then I generate JSF Pages from the Entity classes created on last step, it's also ok.
But when I run the Enterprise application project, I get errors, please see following logs.

But if I generate Entity Class in web project, it can run with no problems.

I have another questions, when I use "JSF Pages from the Entity classes", it will generate some session beans, can I put these session beans on ebj module(project)?

This is my environment:
Product Version: NetBeans IDE 7.2 (Build 201207171143)
Java: 1.7.0_07; Java HotSpot(TM) Client VM 23.3-b01
System: Windows XP version 5.1 running on x86; GBK; en_US (nb)
GlassFish Server 3.1.2
DB: Microsoft SQL Server 2008 Enterprise Edition (64-bit); version: 10.50.2500.0
JDBC Driver: jtds-1.2.6.jar (I put it in "C:\Program Files\glassfish-3.1.2.2\glassfish\lib" also).

This is part of log:

WARNING: Input stream has been finalized or forced closed without being explicitly closed; stream instantiation reported in following stack trace
java.lang.Throwable
	at com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream.<init>(ASURLClassLoader.java:1230)
	at com.sun.enterprise.loader.ASURLClassLoader.getResourceAsStream(ASURLClassLoader.java:878)
	at net.sourceforge.jtds.jdbc.CharsetInfo.<clinit>(CharsetInfo.java:70)
	at net.sourceforge.jtds.jdbc.ConnectionJDBC2.loadCharset(ConnectionJDBC2.java:1416)
	at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:333)
	at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
	at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
	at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:188)
	at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:137)
	at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:115)
	at com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator.createResource(LocalTxConnectorAllocator.java:87)
	at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:907)
	at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1189)
	at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
	at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
	at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512)
	at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944)
	at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230)
	at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511)
	at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245)
	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:170)
	at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:338)
	at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:301)
	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
	at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:113)
	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:123)
	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
	at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:211)
	at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
	at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
	at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
	at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
	at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
	at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:290)
	at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:86)
	at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:141)
	at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:138)
	at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:215)
	at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:224)
	at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:253)
	at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:138)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
	at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
	at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:219)
	at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
	at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
	at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
	at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
	at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
	at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:78)
	at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:253)
	at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
	at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
	at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
	at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.start(GlassFishDecorator.java:63)
	at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishImpl.start(OSGiGlassFishImpl.java:69)
	at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:117)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
	at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:55)

SEVERE: Class [ Ljpa/Label; ] not found. Error while loading [ class jsf.LabelController ]
SEVERE: Class [ Ljpa/Type; ] not found. Error while loading [ class jsf.TypeController ]
SEVERE: Class [ Ljpa/ProjectBaseStatus; ] not found. Error while loading [ class jsf.ProjectBaseStatusController ]
SEVERE: Class [ Ljpa/Modul; ] not found. Error while loading [ class jsf.ModulController ]
SEVERE: Class [ Ljpa/Project; ] not found. Error while loading [ class jsf.ProjectController ]
SEVERE: Class [ Ljpa/ProjectBase; ] not found. Error while loading [ class jsf.ProjectBaseController ]
SEVERE: Class [ Ljpa/Version; ] not found. Error while loading [ class jsf.VersionController ]
SEVERE: Class [ Ljpa/Label; ] not found. Error while loading [ class jsf.LabelController ]
SEVERE: Class [ Ljpa/Type; ] not found. Error while loading [ class jsf.TypeController ]
SEVERE: Class [ Ljpa/ProjectBaseStatus; ] not found. Error while loading [ class jsf.ProjectBaseStatusController ]
SEVERE: Class [ Ljpa/Modul; ] not found. Error while loading [ class jsf.ModulController ]
SEVERE: Class [ Ljpa/Project; ] not found. Error while loading [ class jsf.ProjectController ]
SEVERE: Class [ Ljpa/ProjectBase; ] not found. Error while loading [ class jsf.ProjectBaseController ]
SEVERE: Class [ Ljpa/Version; ] not found. Error while loading [ class jsf.VersionController ].......

WARNING: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units.  Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
INFO: EJB5181:Portable JNDI names for EJB VersionFacade: [java:global/TestLT/TestLT-war/VersionFacade, java:global/TestLT/TestLT-war/VersionFacade!ebj.VersionFacade]
SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbDeployer load method
.....

java.lang.RuntimeException: EJB Container initialization error
	at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:242)
	at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:305)
	at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:108)
	at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
	at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
	at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
	at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
	at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
	at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
	at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: jpa/Version
	at ebj.VersionFacade.<init>(VersionFacade.java:27)
	at ebj.__EJB31_Generated__VersionFacade__Intf____Bean__.<init>(Unknown Source)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at java.lang.Class.newInstance0(Class.java:372)
	at java.lang.Class.newInstance(Class.java:325)
	at com.sun.ejb.containers.BaseContainer.instantiateOptionalEJBLocalBusinessObjectImpl(BaseContainer.java:3887)
	at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:253)
	at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:167)
	at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
	... 33 more
Comment 1 Sergey Petrov 2012-10-05 03:23:18 UTC
It's unclear what's the problem with generated entities classes, do you know what's wrong with generated entities? do you have proper dependencies between modules?
Comment 2 TianQing 2012-10-05 03:54:27 UTC
Thank you Petrov!

I don't know what's wrong with generated entity class, but it seem strange for following log:
SEVERE: Class [ Ljpa/Label; ] not found. Error while loading [ class
jsf.LabelController ]
I use "jpa" as the package name for entiry classes, but it display "Ljpa", what's the "L"?

I checked the dependency, it seems OK, I have three projects:
TestLT2: The enterprise application
TestLT2-ebj: The ejb module
TestLT2-war: The web module
I checked following dependency:
TestLT2: there are two module TestLT2-ebj.jar and TestLT2-war.war in "Java EE modules"
TestLT2-ebj.jar is in "Libraries" of TestLT2-war project.
And I also add "jtds-1.2.6.jar" to the "Libraries" of project TestLT2-ebj and TestLT2-war.

I'm just testing the functions of Netbeans on Java EE supporting, we are present using eclipse, we plan to use Netbeans as the dev environment for our new projects.

BR,
Tian Qing
Comment 3 Sergey Petrov 2012-10-05 04:15:27 UTC
as entities itself are the same for any kind of project, it may be a problem with injection/manageability of control classes etc. do you have context/dependency injection enabled? 
Also there is some hint in your log regarding persistence.xml, there may be a problem, how it was created and can you attach it to the project?
'L' looks like some standard prefix.
Comment 4 TianQing 2012-10-05 05:06:23 UTC
Thank you Petrov!

I tried again with context/dependency injection enabled when create the enterprise application, but it is still the same problem.

I found there are two persistence.xml, one is for web and another is for ejb project, they are all most the same.

Following is persistence.xml for project TestLT3-war.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="TestLT3-warPU" transaction-type="JTA">
    <jta-data-source>lt5_dataSource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

And following is persistence.xml for project TestLT3-ejb.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="TestLT3-ejbPU" transaction-type="JTA">
    <jta-data-source>lt5_dataSource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

BR,
Tian Qing
Comment 5 Jiri Skrivanek 2012-10-05 09:37:56 UTC
It is reproducible with steps from the description:

- create Enterprise application with two projects ebj and web.
- generate Entity Class from DB in ebj project
- generate JSF Pages from the Entity classes in web project
- run EnterpriseApllication project and it fails
Comment 6 TianQing 2012-10-09 02:51:05 UTC
Is there any plan to fix this bug?
Comment 7 David Konecny 2012-10-09 05:32:35 UTC
I would like to look into it tomorrow.
Comment 8 David Konecny 2012-10-09 22:20:12 UTC
> I created a Enterprise application with two projects ebj and web.
> Then I generate Entity Class from DB in ebj project, it's ok.
> Then I generate JSF Pages from the Entity classes created on last step, it's
> also ok.
> But when I run the Enterprise application project, I get errors, please see
> following logs.

The problem here is that EJBs which are defined in Web Project cannot see JPA entities defined in EJB project. I would either:

#1) generate everything into Web project; or
#2) move EJBs into EJB project

In both above cases it will work. Other alternative which could work (I have not tested it) is to move JPA entities from EJB project into J2SE Class Library project and then simply use that library from Web project (while keeping EJBs in Web Project). That should work as well. I cannot remember off-hand what the Java EE spec says about visibility - can Web EE module see JPA entities in EJB EE module or not.

> But if I generate Entity Class in web project, it can run with no problems.
> 
> I have another questions, when I use "JSF Pages from the Entity classes", it
> will generate some session beans, can I put these session beans on ebj
> module(project)?

Yes. If you placed them into separate package just cut and paste the package into EJB project and change name of persistence unit in the EJB itself and everything will work again.

The JSF Pages from Entities wizard is not smart enough to do that automatically for you - that should be either fixed or wizard should not generate broken code.
Comment 9 Martin Fousek 2012-10-10 15:32:16 UTC
I tried to search a lot (2-3 hours) around the visibility but there is terrible documentation and the answer is split in various specifications - at least it looks to me so:
- JavaEE 5 spec. doesn't say much useful around that
- JavaEE 6 spec. says that the web container may have access to the content of any EJB jar files included in the same ear file (JSR-316: chapter 8.3.1)
- Persistence 2.0 spec. speaks about persistence unit visibility, way how should be persistence packaged in the EAR application and its scope: JSR-317 chapters 8.2 and 8.2.2

In any case information still looks quite obfuscated to me. I think, it's something which is not often solving since the optimal structure of EAR looks differently.
- Persistence spec. suggests to bundle persistence.xml with entity classes into the JAR file and include it to the EAR library directory. Persistence Unit should be available to all children modules then. Anyway also the David's solutions #1, #2 work pretty well.

About this issue. Since the entity classes mustn't be probably visible from another EJB (persistence looks to guarantee only access within the same EJB, WAR, AppClient or from the EAR to the all children modules) I suggest to ...
1, show a warning message during the generation when the entity classes came from the EJB project that the generated application mustn't work propertly
2, hide all entity classes of EJBs by generation

Ok guys what do you think? Do you have favourite solution? I vote for the option #1 since we are not sure that it's not situation only of the GF server. And also it would prevent issues like "I have ECs in my EJB which is on the classpath of the WEB project and the generation dialog doesn't show any one of them."
Comment 10 Martin Fousek 2012-10-12 08:05:57 UTC
I forgot that the first panel of the wizard comes from j2ee.persistence. So I'm CCing Sergey.

Sergey does it make sense to you as well - solution #1 or #2? Or do you know more about visibility in these cases?

In any case. I think that something like detection from which projects entities come is possible... BUT to detect it I needed to use in EntityClosure class FileOwnerQuery per every root of CP, add dependency j2ee.persistence on j2ee.api.ejbmodule, check whether the project is EJB one ... I think that it would be quite expensive changes for one warning like that. Do you have better idea? If not I would vote to keep this behaviour as designed now then. :/
Comment 11 Martin Fousek 2012-10-12 08:09:03 UTC
Created attachment 125833 [details]
preview of the patch

I'm attaching draft of the patch. It's not for sure final patch for that but it shows that whole action would not be probably good for the performance. Any other idea would be welcomed.
Comment 12 Sergey Petrov 2012-10-12 10:58:41 UTC
I know not much more about visibility, in my opinion it have sense to show entities but block generation if we know result will fail for gf3.x and a few more servers.
Is j2ee.api.ejbmodule in java cluster?
Comment 13 Sergey Petrov 2012-10-12 11:06:05 UTC
Just check myself, this dependency isn't possible as j2ee.api.ejbmodule in enterprise cluster.

Instead of new dependency addition it may have sense to look if some additional meths can be added into some of persistence providers realized for different type of modules, like PersistenceScopeProvider, PersistenceEnvironment etc. Just need to remember about maven also with maven ejb project.
Comment 14 Sergey Petrov 2012-10-12 11:56:08 UTC
And it's implemented already in
org.netbeans.modules.j2ee.persistence.wizard.Util::isEjbModule(Project project)
Comment 15 Martin Fousek 2012-10-12 12:16:03 UTC
(In reply to comment #13)
> Just check myself, this dependency isn't possible as j2ee.api.ejbmodule in
> enterprise cluster.

That's really good point. I didn't check that before.

(In reply to comment #14)
> And it's implemented already in
> org.netbeans.modules.j2ee.persistence.wizard.Util::isEjbModule(Project project)

Thanks, that will definitely help a lot.

Now remains only the expensive FileOwnerQuery on COMPILE CP roots. I would like wait for David's opinion and if he would agree I can finish the patch with the change that just the warning appear - I think that both of us agreed on that.
Comment 16 Sergey Petrov 2012-10-12 12:20:24 UTC
a bit of 'googling' and http://stackoverflow.com/questions/11951193/ejb3-code-in-ear-cant-see-jpa-entities-defined-in-ejb-client-jar-in-lib-thr
it may work in this case also.
Comment 17 Martin Fousek 2012-10-12 12:32:52 UTC
(In reply to comment #16)
> a bit of 'googling' and
> http://stackoverflow.com/questions/11951193/ejb3-code-in-ear-cant-see-jpa-entities-defined-in-ejb-client-jar-in-lib-thr
> it may work in this case also.

I tried that before and it didn't work. It's probably due to no visibility ensure I suppose. That's why I recommended to use EAR library folder as the best place for the JPA resource .jar - it's recommended by most of papers/docs I read.
Comment 18 David Konecny 2012-10-14 22:30:07 UTC
> I tried to search a lot (2-3 hours) around the visibility but there is terrible
> documentation and the answer is split in various specifications - at least it
> looks to me so:
> - JavaEE 5 spec. doesn't say much useful around that
> - JavaEE 6 spec. says that the web container may have access to the content of
> any EJB jar files included in the same ear file (JSR-316: chapter 8.3.1)
> - Persistence 2.0 spec. speaks about persistence unit visibility, way how
> should be persistence packaged in the EAR application and its scope: JSR-317
> chapters 8.2 and 8.2.2

Good job Martin. It is tricky because specs can be vague and app servers sometimes implement it differently in different versions.

> I suggest to ...
> 1, show a warning message during the generation when the entity classes came
> from the EJB project that the generated application mustn't work propertly
> 2, hide all entity classes of EJBs by generation
> 
> Ok guys what do you think? Do you have favourite solution? I vote for the
> option #1

#1 sounds good to me.

> [...]I think that it
> would be quite expensive changes for one warning like that. Do you have better
> idea? If not I would vote to keep this behaviour as designed now then. :/

I'm OK with not fixing this issue too. 

> Now remains only the expensive FileOwnerQuery on COMPILE CP roots. I would like
> wait for David's opinion and if he would agree I can finish the patch with the
> change that just the warning appear - I think that both of us agreed on that.

I agree with that too. I'm not too concerned with FOQ being expensive.

Thanks!
Comment 19 Martin Fousek 2012-10-15 06:02:17 UTC
Thanks David for your comment, really appreciate - your opinion was important to me! After my vacation I'll try to finish the patch and include it into the repo. It can be removed anytime when it would bring bad performance, so we can try to fix that and remove it in case it would make us perf. troubles.
Comment 20 Martin Fousek 2012-10-22 07:44:10 UTC
Ok so there was added warning complaining about visibility on project's classpath in the case when any of entities came from an EJB module.

BTW, if would the fileOwnerQuery make performance troubles I would vote for removing that fix and closing it as wontfix. I didn't watch any slowdowns yet. 

Fixed in web-main #de722e8d96ce.
Comment 21 Quality Engineering 2012-10-23 12:10:46 UTC
Integrated into 'main-golden', will be available in build *201210231040* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/de722e8d96ce
User: Martin Fousek <marfous@netbeans.org>
Log: #219565 - Entity classes generated in ejb project can not be found in glashfish 3.1.2