Impossible to use an app in stage/dist mode with jpa with play 2.4.0
Create a project with play 2.4.0 and jpa support. The application works just fine in dev mode but when you use it in stage mode each time you try to access a jpa class there is an error that says the classes annotated with @Entity are not mapped.
It seems there is a problem with jpa support in this mode.
I tried this on a simple fresh test project and the error occurs
What's the error message?
The full log can be found here : https://gist.github.com/scesbron/3cf5d8e8732697612441
@scesbron Could you provide the test project you created to reproduce the issue?
Hi
Here is a link to download the project
https://chezsoi.org/owncloud/index.php/s/dRbauJGxWtGevNq
Regards Seb
@scesbron The download doesn't work for me... It gets stuck after a few percent.
Another location : http://dl.free.fr/getfile.pl?file=/fCZIJK5e
I can confirm this bug, it is working in dev but not when using the stage task. I uploaded the test project @scesbron provided at https://github.com/mkurz/play24-hibernate-stage.
Maybe this has something to do with class loading?
Also when I change this line to
return JPA.em().createQuery("from models.Test", Test.class).getResultList(); // added "models." prefix
the exception now changes from the original ...is not mapped... exception to an ArrayIndexOutOfBoundsException: 0 (full log here)
I can also confirm the exact same test project is working fine with Play 2.3.x (with the stage task).
I created a 2.3.x branch where I added a commit which downgrades the test project to Play 2.3.9.
So this definitely seems like a regression in Play 2.4. Could someone else have a look what's wrong here? Thanks!
I agree this is probably a ClassLoader issue. See #4594.
Is there any workaround for this bug ? Or do you think it can be resolved soon.
This bug prevents us to put our application in production with play 2.4.0 so I want to know if I have to downgrade to 2.3.9 or no.
The only workaround that works is manually declaring your entities in persistence.xml using the <class> tag. It is not DRY, but works.
We will fix this bug, but we can't give you an ETA.
Thx for the tip, your workaround works and even if it is not dry it will allow me to put my project in production.
I wonder if it's related to the duplication of resources on the classpath?
Could you try setting:
PlayKeys.externalizeResources := false
in your build.sbt? Doing this will mean that resources won't be copied to the conf directory in your production deployment. Having them externalized caused #4512, which is already fixed and will be in 2.4.1.
@jroper That's it! I added PlayKeys.externalizeResources := false to the test project I provided above and I can confirm it is working now. When I remove it the exception occurs again. So we just have to wait for 2.4.1 :smile:
It works with @jroper key in the build.sbt, no need to declare classes in the persistence.xml file.
Does this config as some side effects on something else ?
When externalizeResources is true, all the resources from your project (everything in the conf directory, basically) are copied to the conf directory of your distribution artifact, and that directory is added to the classpath of the project. When it's false, the resources aren't copied there, but are still on the classpath due to the fact that they are bundled in the jar artifact for your project, which is in the lib directory of the distribution artifact.
So the effect is that you can't edit the configuration in the conf directory of your extracted distribution.
#4522 fixes the duplicate resource issue by ensuring that when externalizeResources is true, the resources are not added to your projects jar (actually, it builds a separate jar that excludes the resources and adds that to the distribution instead).
Anyway, closing because it's fixed in #4522.
It seems there is a regression with PlayKeys.externalizeResources := false
Now when I put my app into production I have this exception : https://gist.github.com/scesbron/f3dceac53e99bf029871
It seems there is a problem for the Crypto class to find its config.
If I comment the line in build.sbt the problem go away
@scesbron do you have play.crypto.secret (or the deprecated application.secret) configured in application.conf? This is a required configuration in production mode.
Yes I have and the weird thing is that I just have to comment the PlayKeys.externalizeResources and my app work
I just upgraded from 2.4.0 to 2.4.1. I was under the impression that I should now be able to remove my
Full log: https://gist.github.com/dan-lind/4ad585ce6ecd555eadd4