Created attachment 97554 [details]
1. Create a new Java class library project
2. Create some entity classes from database
3. Add the eclipselink-jpa-modelgen jar file from the EclipseLink distribution to the classpath
4. Build the project - works fine
5. Create a new class under Test Packages
6. Run tests for the project
=> Fails with the message in the attachment.
The question is whether the fix should be on the NetBeans side (making sure we don't put the modelgen jar file on the tests classpath if persistence.xml does not exist), or on the EclipseLink side (be more tolerant to missing persistence.xml). My preference would be on the EclipseLink side.
Right how this bug is not that pronounced because of step 3, but when we re-enable issue 178108 (metamodel generation by default), this bug will become more serious, as it will fail out of the box.
I can run selected test, but "Test" for entire project fails with ap problem.
What I can see if I have entity in src and entity in test, both are processed by ap correctly and both have metamodel generated and present in code completion.
/tried j2se and ap in editor support, in case of web project entities from test are not processed, it may be another issue.
I am looking at it.
The problem is that the eclipselink requires the persistence.xml file. The best fix if possible is on the eclipselink side (if there is no persistence.xml and there are no @Entity classes do nothing). If not doable on eclipselink side Sergey can extend his indexer, which now copies the persistence.xml into caches, to put it also into tests cache root. This is ugly but it should work. We will also need such a hack in the build-impl.xml for the case when compile on save is off.
Is there any difference with build and with run classpath for tests?
Eclipselink see persistence.xml if tests are executed and can access db/persist entities etc. But it may be because main part access persistence.xml another way then annotation processor.
Also as I said before I got metamodel generated for entity in test sources in j2se project in current build, i.e. without additional hack for indexer.
Yes, there is a difference.
For source compile, the source root contains the persistence.xml and it's copied into caches.
For tests the source root is test folder which has on its classpath build/classes (result of compilation of src folder). There is no persistence.xml among sources or class output (caches).
In the runtime the persistence.xml is probably loaded by ClassLoader.getResource which looks up in all jar files on classpath. In compile time the AP is looking for persistence.xml only in CLASS_OUTPUT (where your indexer copies it from src root).
>Also as I said before I got metamodel generated for entity in test sources in j2se project in current build.
But you had a persistence.xml in the test root, right? For the j2seproject works the original "hack" before the indexer was integrated. When AP is looking for file in CLASS_OUTPUT and it's not found there we are trying to find it among SOURCE.
>But you had a persistence.xml in the test root, right?
No, I'll retry tomorrow, but I had persistence.xml in usual location only.
I'll wait for 2.0.3 for integration.
For now, I think we can downgrade to P3, what do you think?
As it was considered el issue and is fixed on el side, in my opinion this one issue may be closed now.
if there are no objections.
now metamodel jar isn't added by default
later eclipselink versions will no have this issue
no actions from nb is planned - close as won't fix