• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to generate table schema from persistence.xml of jpa 2.1?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to generate table schema with script file with eclipse and wildfly 8.1

This is my persistence.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">

<persistence-unit name="MyFamily">
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>

<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="script-then-metadata"/>
<property name="javax.persistence.schema-generation.create-database-schemas" value="true"/>
<property name="javax.persistence.schema-generation.scripts.drop-script-source" value="META-INF/drop-script.jdbc"/>
<property name="javax.persistence.schema-generation.scripts.create-script-source" value="META-INF/create-script.jdbc"/>
<property name="javax.persistence.sql-load-script-source" value="META-INF/load-script.jdbc"/>
<property name="org.hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
</properties>
</persistence-unit>
</persistence>


And these are entity source and script files.

=== Entity

@Entity
@EntityListeners(Alarm.class)
@Table(name="family", indexes={@Index(columnList="EMP_ID"), @Index(columnList="EMP_NAME")})
public class Members implements Serializable {

@Id
@Column(name = "EMP_ID")
private String ID;

@Column(name = "EMP_Passwd")
private String Passwd;

@Column(name = "EMP_Age")
private int Age;

@Column(name = "EMP_Name")
private String Name;

=== create-script.jdbc

CREATE TABLE family (
EMP_ID VARCHAR(255) NOT NULL,
EMP_PASSWD VARCHAR(255) NOT NULL,
EMP_AGE INT NOT NULL,
EMP_NAME VARCHAR(255) NOT NULL,

PRIMARY KEY(EMP_ID)
)

But deployment throws the following exception:

15:05:58,728 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 55) MSC000001: Failed to start service jboss.persistenceunit."EJBLoginEAR.ear/EJBLoginModule.jar#MyFamily": org.jboss.msc.service.StartException in service jboss.persistenceunit."EJBLoginEAR.ear/EJBLoginModule.jar#MyFamily": javax.persistence.PersistenceException: Schema generation configuration indicated to include CREATE scripts, but no script was specified
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_60]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_60]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: Schema generation configuration indicated to include CREATE scripts, but no script was specified
at org.hibernate.jpa.internal.schemagen.JpaSchemaGenerator$Generation.buildCreateSourceList(JpaSchemaGenerator.java:284) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.internal.schemagen.JpaSchemaGenerator$Generation.execute(JpaSchemaGenerator.java:133) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.internal.schemagen.JpaSchemaGenerator.performGeneration(JpaSchemaGenerator.java:76) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
... 8 more

15:05:58,731 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) JBAS014613: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"EJBLoginEAR.ear/EJBLoginModule.jar#MyFamily\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"EJBLoginEAR.ear/EJBLoginModule.jar#MyFamily\": javax.persistence.PersistenceException: Schema generation configuration indicated to include CREATE scripts, but no script was specified
Caused by: javax.persistence.PersistenceException: Schema generation configuration indicated to include CREATE scripts, but no script was specified"}}


How can I generate db schema with script files of persistence.xml in wildfly 8?

Your help will be appreciated!
 
Joseph Hwang
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved it myself.
Reference site is

https://github.com/hantsy/ee7-sandbox/wiki/jpa-scripts

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic