You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Phani Madgula <ph...@gmail.com> on 2008/12/16 06:28:14 UTC

Fwd: Generate Script SQL Script files.

Forwaring this mail to dev list.

Thanks in advance.
Phani


---------- Forwarded message ----------
From: Phani Madgula <ph...@gmail.com>
Date: Wed, 10 Dec 2008 15:27:28 +0530
Subject: Generate Script SQL Script files.
To: users@openjpa.apache.org

Hi,
I have the following persistence.xml file.
***************
<?xml version="1.0" encoding="UTF-8" ?>
- <persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">

- <persistence-unit name="Tutorial" transaction-type="JTA">
  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  <non-jta-data-source>ProductDS</non-jta-data-source>

  <class>samples.jpa.Product</class>
  <class>samples.jpa.Book</class>

- <properties>

  <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys=true,sqlFile=./logs/jpaSQL.log)"
/>

  <property name="openjpa.Log"
value="DefaultLevel=INFO,SQL=TRACE,File=./logs/jpaEnhancerLog.log,Runtime=INFO,Tool=INFO"
/>

  </properties>

  </persistence-unit>
  </persistence>
**********************

I wanted JPA to generate SQL scripts for entities in my WAR file into
"/logs/jpaSQL.log" file as configured above during runtime.

When I used "sqlFile=./logs/jpaSQL.log", it threw an exception as below.

********************
.servlet.ServletException: <openjpa-1.0.2-r420667:627158 nonfatal
general error> org.apache.openjpa.persistence.PersistenceException:
There was an error while setting up the configuration plugin option
"SynchronizeMappings". The plugin was of type
"org.apache.openjpa.jdbc.meta.MappingTool". Setter methods for the
following plugin properties were not available in that type:
[sqlFile]. Possible plugin properties are: [ACTIONS, ACTION_ADD,
ACTION_BUILD_SCHEMA, ACTION_DROP, ACTION_EXPORT, ACTION_IMPORT,
ACTION_REFRESH, ACTION_VALIDATE, DropUnusedComponents, ForeignKeys,
IgnoreErrors, Indexes, MODE_ANN_MAPPING, MODE_MAPPING,
MODE_MAPPING_INIT, MODE_META, MODE_NONE, MODE_QUERY, MappingWriter,
MetaDataFile, PrimaryKeys, ReadSchema, Repository, SCHEMA_ACTION_NONE,
SchemaAction, SchemaGroup, SchemaTool, SchemaWriter, Sequences].
Ensure that your plugin configuration string uses key values that
correspond to setter methods in the plugin class.
	samples.jpa.Test.doGet(Test.java:63)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
*************************

Looks like "sqlFile" is not a valid option for "buildSchema" action.
Currenty I am working around this problem by generating SQL scripts in
"/logs/jpaEnhancerLog and manually copying the SQL statements.

Questions??

How do I generate SQL script files into a seperate file?? WHat
configurations are required for forward mapping in a runtime
environment??

Thanks in advance.
Phani

Re: Generate Script SQL Script files.

Posted by Albert Lee <al...@gmail.com>.
Phani,

I don't think openjpa is complaining about the sqlFile option.

>From the openjpa manual, SchemaAction takes the following values:

-schemaAction/-sa <add | refresh | drop | build | retain | reflect |
createDB | dropDB | import | export | none> :

The other way to generate sql ddl is described in :

7.1.2. Generating DDL SQL
The examples below show how to use the mapping tool to generate DDL SQL
scripts, rather than modifying the database directly.
Example 7.5. Create DDL for Current Mappings
This example uses your existing mappings to determine the needed schema,
then writes the SQL to create that schema to create.
sql.
java org.apache.openjpa.jdbc.meta.MappingTool -schemaAction build -sql
create.sql Magazine.java
Example 7.6. Create DDL to Update Database for Current Mappings
This example uses your existing mappings to determine the needed schema. It
then writes the SQL to add any missing tables and
columns to the current schema to update.sql.
java org.apache.openjpa.jdbc.meta.MappingTool -sql update.sql Magazine.java

Albert Lee.

On Mon, Dec 15, 2008 at 11:28 PM, Phani Madgula <
phanibalaji.madgula@gmail.com> wrote:

> Forwaring this mail to dev list.
>
> Thanks in advance.
> Phani
>
>
> ---------- Forwarded message ----------
> From: Phani Madgula <ph...@gmail.com>
> Date: Wed, 10 Dec 2008 15:27:28 +0530
> Subject: Generate Script SQL Script files.
> To: users@openjpa.apache.org
>
> Hi,
> I have the following persistence.xml file.
> ***************
> <?xml version="1.0" encoding="UTF-8" ?>
> - <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
> version="1.0">
>
> - <persistence-unit name="Tutorial" transaction-type="JTA">
>
>  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>  <non-jta-data-source>ProductDS</non-jta-data-source>
>
>  <class>samples.jpa.Product</class>
>  <class>samples.jpa.Book</class>
>
> - <properties>
>
>  <property name="openjpa.jdbc.SynchronizeMappings"
>
> value="buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys=true,sqlFile=./logs/jpaSQL.log)"
> />
>
>  <property name="openjpa.Log"
>
> value="DefaultLevel=INFO,SQL=TRACE,File=./logs/jpaEnhancerLog.log,Runtime=INFO,Tool=INFO"
> />
>
>  </properties>
>
>  </persistence-unit>
>  </persistence>
> **********************
>
> I wanted JPA to generate SQL scripts for entities in my WAR file into
> "/logs/jpaSQL.log" file as configured above during runtime.
>
> When I used "sqlFile=./logs/jpaSQL.log", it threw an exception as below.
>
> ********************
> .servlet.ServletException: <openjpa-1.0.2-r420667:627158 nonfatal
> general error> org.apache.openjpa.persistence.PersistenceException:
> There was an error while setting up the configuration plugin option
> "SynchronizeMappings". The plugin was of type
> "org.apache.openjpa.jdbc.meta.MappingTool". Setter methods for the
> following plugin properties were not available in that type:
> [sqlFile]. Possible plugin properties are: [ACTIONS, ACTION_ADD,
> ACTION_BUILD_SCHEMA, ACTION_DROP, ACTION_EXPORT, ACTION_IMPORT,
> ACTION_REFRESH, ACTION_VALIDATE, DropUnusedComponents, ForeignKeys,
> IgnoreErrors, Indexes, MODE_ANN_MAPPING, MODE_MAPPING,
> MODE_MAPPING_INIT, MODE_META, MODE_NONE, MODE_QUERY, MappingWriter,
> MetaDataFile, PrimaryKeys, ReadSchema, Repository, SCHEMA_ACTION_NONE,
> SchemaAction, SchemaGroup, SchemaTool, SchemaWriter, Sequences].
> Ensure that your plugin configuration string uses key values that
> correspond to setter methods in the plugin class.
>        samples.jpa.Test.doGet(Test.java:63)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
> *************************
>
> Looks like "sqlFile" is not a valid option for "buildSchema" action.
> Currenty I am working around this problem by generating SQL scripts in
> "/logs/jpaEnhancerLog and manually copying the SQL statements.
>
> Questions??
>
> How do I generate SQL script files into a seperate file?? WHat
> configurations are required for forward mapping in a runtime
> environment??
>
> Thanks in advance.
> Phani
>



-- 
Albert Lee.