{"id":1191,"date":"2011-01-23T13:41:53","date_gmt":"2011-01-23T13:41:53","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1191"},"modified":"2011-01-23T15:24:51","modified_gmt":"2011-01-23T15:24:51","slug":"eclipse-generate-tables-from-entities-failure-with-eclipslink-2-1-2-glassfish-v3-0-1","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1191","title":{"rendered":"Eclipse JPA table generation fails with Eclipslink 2.1.2, Glassfish V3.0.1"},"content":{"rendered":"<p>I was attempting to create a database for a new project which just contained entities \u2013 I had imported the entity classes from Enterprise Architect and added the required annotations, getters &amp; setters etc.<\/p>\n<p>My first attempt used the following <em>persistence.xml<\/em> (I have removed most of the classes for the example)<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br \/>\n&lt;persistence version=&#8221;2.0&#8243; xmlns=<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\">http:\/\/java.sun.com\/xml\/ns\/persistence<\/a><br \/>\nxmlns:xsi=<a href=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\">http:\/\/www.w3.org\/2001\/XMLSchema-instance<\/a><br \/>\nxsi:schemaLocation=&#8221;<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\">http:\/\/java.sun.com\/xml\/ns\/persistence<\/a> <a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_2_0.xsd&quot;\">http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_2_0.xsd&#8221;<\/a>&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 &lt;persistence-unit name=&#8221;Test&#8221; transaction-type=&#8221;RESOURCE_LOCAL&#8221;&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;\/provider&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;non-jta-data-source&gt;jdbc\/TestPool&lt;\/non-jta-data-source&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.Address&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.AddressLine&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.Campaign&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.CampaignText&lt;\/class&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;exclude-unlisted-classes&gt;false&lt;\/exclude-unlisted-classes&gt;\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;properties&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.logging.level&#8221; value=&#8221;INFO&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.target-server&#8221; value=&#8221;None&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;!&#8211; &lt;property name=&#8221;eclipselink.target-server&#8221; value=&#8221;SunAS9&#8243; \/&gt;&#8211;&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.target-database&#8221; value=&#8221;Oracle&#8221; \/&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.ddl-generation.output-mode&#8221; value=&#8221;database&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/properties&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0 &lt;\/persistence-unit&gt;<br \/>\n&lt;\/persistence&gt;<\/p>\n<p>\u00a0Having created the database and validated the connection\/datasource etc., I attempted to create the tables from\u00a0 Eclipse by right clicking the project and selecting <em>JPA Tools\/Create Tables from Entities\u2026<\/em><\/p>\n<p>This resulted in the following error:-<\/p>\n<p><em>[EL Config]: Connection(5226838)&#8211;connecting(DatabaseLogin(<br \/>\n\u00a0\u00a0\u00a0 platform=&gt;OraclePlatform<br \/>\n\u00a0\u00a0\u00a0 user name=&gt; &#8220;Test&#8221;<br \/>\n\u00a0\u00a0\u00a0 connector=&gt;JNDIConnector datasource name=&gt;jdbc\/TestPool<br \/>\n))<br \/>\n[EL Severe]: Local Exception Stack:<br \/>\nException [EclipseLink-7060] (Eclipse Persistence Services &#8211; 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.ValidationException<br \/>\nException Description: Cannot acquire data source [jdbc\/TestPool].<br \/>\nInternal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:\u00a0 java.naming.factory.initial<\/em><\/p>\n<p>The error occurred even though the data source was being used outside the container as a non-jta data source (this worked previously for JPA1\/Glassfish V2, allowing JPA to be used outside the container but still using a datasource defined in Glassfish). A previous post <a href=\"http:\/\/salientsoft.co.uk\/?p=295\"><strong>here<\/strong><\/a> (in the section <em>Notes on Persistence.xml)<\/em> also reports that when running outside the container, it is vital to have <em>eclipselink.target-server defaulted or set to none.<\/em> In this case, the setting caused no difference either way. After a fair bit of research\/Googling, I could not find the cause of the problem, so I simply reverted to specifying the connection explicitly in <em>persistence.xml,<\/em>\u00a0 without using the connection defined in Glassfish at all.<\/p>\n<p>This worked correctly. I will not need to create the database very often, and it only involved tweaking a few lines in the file, so I\u2019m happy to live with it. Here is my modified <em>persistence.xml<\/em> which uses a direct connection specified in the file. This version created the database correctly. Note that as detailed<strong> <\/strong><a href=\"http:\/\/salientsoft.co.uk\/?p=1102\"><strong>in this post here<\/strong><\/a> (near the bottom of the post), the property names for JDBC url, user, password and driver have now been standardised and are no longer eclipslink specific.<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br \/>\n&lt;persistence version=&#8221;2.0&#8243; xmlns=&#8221;<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence&quot;\">http:\/\/java.sun.com\/xml\/ns\/persistence&#8221;<\/a> xmlns:xsi=&#8221;<a href=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\">http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;<\/a> xsi:schemaLocation=&#8221;<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\">http:\/\/java.sun.com\/xml\/ns\/persistence<\/a> <a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_2_0.xsd&quot;\">http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_2_0.xsd&#8221;<\/a>&gt;<\/p>\n<p>\u00a0\u00a0\u00a0 &lt;persistence-unit name=&#8221;Test&#8221; transaction-type=&#8221;RESOURCE_LOCAL&#8221;&gt;\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 &lt;!&#8211; &lt;persistence-unit name=&#8221;Test&#8221; transaction-type=&#8221;JTA&#8221;&gt;&#8211;&gt;<br \/>\n\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;\/provider&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0 &lt;!&#8211;&lt;jta-data-source&gt;jdbc\/TestPool&lt;\/jta-data-source&gt;&#8211;&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0 &lt;!&#8211;&lt;non-jta-data-source&gt;jdbc\/TestPool&lt;\/non-jta-data-source&gt;&#8211;&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.Address&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.AddressLine&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.Campaign&lt;\/class&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.Test.domain.CampaignText&lt;\/class&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;exclude-unlisted-classes&gt;false&lt;\/exclude-unlisted-classes&gt;\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;properties&gt;\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=&#8221;javax.persistence.jdbc.url&#8221; value=&#8221;jdbc:oracle:thin:@localhost:1521:xe&#8221;\/&gt;\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;javax.persistence.jdbc.user&#8221; value=&#8221;Test&#8221;\/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;javax.persistence.jdbc.password&#8221; value=&#8221;Test&#8221;\/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;javax.persistence.jdbc.driver&#8221; value=&#8221;oracle.jdbc.OracleDriver&#8221;\/&gt;\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.logging.level&#8221; value=&#8221;INFO&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.target-server&#8221; value=&#8221;None&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;!&#8211; &lt;property name=&#8221;eclipselink.target-server&#8221; value=&#8221;SunAS9&#8243; \/&gt;&#8211;&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.target-database&#8221; value=&#8221;Oracle&#8221; \/&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;property name=&#8221;eclipselink.ddl-generation.output-mode&#8221; value=&#8221;database&#8221; \/&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/properties&gt;<br \/>\n\u00a0\u00a0\u00a0\u00a0 &lt;\/persistence-unit&gt;<br \/>\n&lt;\/persistence&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was attempting to create a database for a new project which just contained entities \u2013 I had imported the entity classes from Enterprise Architect and added the required annotations, getters &amp; setters etc. My first attempt used the following persistence.xml (I have removed most of the classes for the example) &lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt; &lt;persistence [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[13,9,137,40,182,16],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1191"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1191"}],"version-history":[{"count":7,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1194,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions\/1194"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}