playframework icon indicating copy to clipboard operation
playframework copied to clipboard

Impossible to use an app in stage/dist mode with jpa with play 2.4.0

Open scesbron opened this issue 11 years ago • 60 comments

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

scesbron avatar Jun 01 '15 05:06 scesbron

What's the error message?

richdougherty avatar Jun 01 '15 06:06 richdougherty

The full log can be found here : https://gist.github.com/scesbron/3cf5d8e8732697612441

scesbron avatar Jun 01 '15 06:06 scesbron

@scesbron Could you provide the test project you created to reproduce the issue?

mkurz avatar Jun 01 '15 06:06 mkurz

Hi

Here is a link to download the project

https://chezsoi.org/owncloud/index.php/s/dRbauJGxWtGevNq

Regards Seb

scesbron avatar Jun 01 '15 07:06 scesbron

@scesbron The download doesn't work for me... It gets stuck after a few percent.

mkurz avatar Jun 01 '15 07:06 mkurz

Another location : http://dl.free.fr/getfile.pl?file=/fCZIJK5e

scesbron avatar Jun 01 '15 07:06 scesbron

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)

mkurz avatar Jun 01 '15 08:06 mkurz

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!

mkurz avatar Jun 01 '15 08:06 mkurz

I agree this is probably a ClassLoader issue. See #4594.

richdougherty avatar Jun 01 '15 23:06 richdougherty

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.

scesbron avatar Jun 03 '15 07:06 scesbron

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.

marcospereira avatar Jun 03 '15 13:06 marcospereira

Thx for the tip, your workaround works and even if it is not dry it will allow me to put my project in production.

scesbron avatar Jun 03 '15 13:06 scesbron

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 avatar Jun 03 '15 13:06 jroper

@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:

mkurz avatar Jun 03 '15 13:06 mkurz

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 ?

scesbron avatar Jun 03 '15 13:06 scesbron

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.

jroper avatar Jun 03 '15 13:06 jroper

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 avatar Jun 04 '15 13:06 scesbron

@scesbron do you have play.crypto.secret (or the deprecated application.secret) configured in application.conf? This is a required configuration in production mode.

marcospereira avatar Jun 04 '15 14:06 marcospereira

Yes I have and the weird thing is that I just have to comment the PlayKeys.externalizeResources and my app work

scesbron avatar Jun 04 '15 14:06 scesbron

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 declared entities in persistence.xml. But when I do, I once again get "Unknown entity". Did I missunderstand something?

Full log: https://gist.github.com/dan-lind/4ad585ce6ecd555eadd4

dan-lind avatar Jun 24 '15 20:06 dan-lind