I’ve been making some experiments with the Play Framework (version 2.4.2) and JPA integration (with Hibernate – version 4.3.10). I was trying to make Hibernate generate the SQL Schema based on the JPA annotations I had in my entity classes and stumbled upon the error you see on the title, with the following stack trace:
[ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, javax.persistence.PersistenceException: Scripting was requested, but no target was specified at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:35) at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:30) while locating play.db.jpa.DefaultJPAApi$JPAApiProvider while locating play.db.jpa.JPAApi
I found that there are some JPA properties to make the provider (in my case, Hibernate) generate the scripts for you (standard properties, no need to use hibernate.hbm2ddl.auto in the persistence.xml file). I’ve found that link through this great answer on stackoverflow.
One of the properties is this:
<property name=“javax.persistence.schema-generation.scripts.action” value=“none / drop / drop-and-create / create “/>
Which when I added to my persistence.xml with any of the values – drop/drop-and-create/create gave me the said error because I didn’t specify where to create the scripts. That’s what the following properties are for:
You have to tell the JPA provider where to create the scripts, hence the error “scripting requested, but no target specified“.
Add the following properties:
- <property name=“javax.persistence.schema-generation.scripts.action” value=“drop-and-create”/>
- <property name=“javax.persistence.schema-generation.scripts.drop-target” value=“conf/db/drop-schema.sql”/>
- <property name=“javax.persistence.schema-generation.scripts.create-target” value=“conf/db/create-schema.sql”/>
You then get the scripts generated to conf/db/. Hope that helps someone