{"id":378,"date":"2015-08-14T10:31:04","date_gmt":"2015-08-14T10:31:04","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=378"},"modified":"2015-08-14T10:31:04","modified_gmt":"2015-08-14T10:31:04","slug":"jpa-generate-schema-scripting-was-requested-but-no-target-was-specified","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2015\/08\/14\/jpa-generate-schema-scripting-was-requested-but-no-target-was-specified\/","title":{"rendered":"JPA Generate Schema &#8211; Scripting was requested, but no target was specified"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>I&#8217;ve been making some experiments with the <a href=\"https:\/\/playframework.com\/\">Play Framework<\/a>\u00a0(version 2.4.2) and <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javaee\/tech\/persistence-jsp-140049.html\">JPA<\/a> integration (with <a href=\"http:\/\/hibernate.org\/\">Hibernate<\/a>\u00a0&#8211; version 4.3.10).\u00a0I 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:<\/p>\n<p><em>[ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, javax.persistence.PersistenceException: <strong>Scripting was requested, but no target was specified<\/strong> at play.db.jpa.DefaultJPAApi$JPAApiProvider.&lt;init&gt;(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<\/em><\/p>\n<p>I found that there are some <a href=\"https:\/\/blogs.oracle.com\/arungupta\/entry\/jpa_2_1_schema_generation\">JPA properties<\/a>\u00a0to make the provider (in my case, Hibernate) generate the scripts for you (standard properties, no need to use\u00a0<em>hibernate.hbm2ddl.auto<\/em> in the persistence.xml file). I&#8217;ve found that link through this <a href=\"http:\/\/stackoverflow.com\/questions\/27314165\/generate-ddl-script-at-maven-build-with-hibernate4-jpa-2-1\">great answer on stackoverflow<\/a>.<\/p>\n<p>One of the properties is this:<\/p>\n<p class=\"p1\"><em><span class=\"s1\">&lt;<\/span><span class=\"s2\">property<\/span> <span class=\"s4\">name<\/span><span class=\"s3\">=<\/span>&#8220;javax.persistence.schema-generation.scripts.action&#8221; <span class=\"s4\">value<\/span><span class=\"s3\">=<\/span>&#8220;none \/ drop \/ drop-and-create \/ create\u00a0&#8220;<span class=\"s1\">\/&gt;<\/span><\/em><\/p>\n<p class=\"p1\">Which when\u00a0I added to my\u00a0persistence.xml with any of the values &#8211;\u00a0<em>drop\/drop-and-create\/create<\/em>\u00a0 gave me\u00a0the said error <strong>because\u00a0I didn&#8217;t specify where to create<\/strong> the scripts. That&#8217;s what the following properties are for:<\/p>\n<ul>\n<li class=\"p1\"><em>javax.persistence.schema-generation.scripts.create-target<\/em><\/li>\n<li class=\"p1\"><em>javax.persistence.schema-generation.scripts.drop-target<\/em><\/li>\n<\/ul>\n<p>You have to tell the JPA provider where to create the scripts, hence the error &#8220;<strong>scripting requested, but no target specified<\/strong>&#8220;.<\/p>\n<h2>The solution<\/h2>\n<p>Add the following properties:<\/p>\n<ul>\n<li class=\"p1\"><em><span class=\"s1\">&lt;<\/span><span class=\"s2\">property<\/span> <span class=\"s4\">name<\/span><span class=\"s3\">=<\/span>&#8220;javax.persistence.schema-generation.scripts.action&#8221; <span class=\"s4\">value<\/span><span class=\"s3\">=<\/span>&#8220;drop-and-create&#8221;<span class=\"s1\">\/&gt;<\/span><\/em><\/li>\n<li class=\"p1\"><em><span class=\"s1\">&lt;<\/span><span class=\"s2\">property<\/span> <span class=\"s4\">name<\/span><span class=\"s3\">=<\/span>&#8220;javax.persistence.schema-generation.scripts.drop-target&#8221; <span class=\"s4\">value<\/span><span class=\"s3\">=<\/span>&#8220;conf\/db\/drop-schema.sql&#8221;<span class=\"s1\">\/&gt;<\/span><\/em><\/li>\n<li class=\"p1\"><em><span class=\"s1\">&lt;<\/span><span class=\"s2\">property<\/span> <span class=\"s4\">name<\/span><span class=\"s3\">=<\/span>&#8220;javax.persistence.schema-generation.scripts.create-target&#8221; <span class=\"s4\">value<\/span><span class=\"s3\">=<\/span>&#8220;conf\/db\/create-schema.sql&#8221;<span class=\"s1\">\/&gt;<\/span><\/em><\/li>\n<\/ul>\n<p>You then get the scripts generated to <strong>conf\/db<\/strong>\/.\u00a0Hope that helps someone \ud83d\ude42<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, I&#8217;ve been making some experiments with the Play Framework\u00a0(version 2.4.2) and JPA integration (with Hibernate\u00a0&#8211; version 4.3.10).\u00a0I was trying to make Hibernate generate the SQL Schema based on the JPA annotations I had in my entity classes and &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2015\/08\/14\/jpa-generate-schema-scripting-was-requested-but-no-target-was-specified\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42],"tags":[43,45,41,40],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/378"}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":6,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":385,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/378\/revisions\/385"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}