You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Frank Schwarz <fr...@gmx.de> on 2008/03/10 11:08:57 UTC

generate DDL script without database access

Hi,

is there a possibility to let OpenJPA create a SQL DDL script without
accessing the database? I would like to apply this script later on to an
empty database.

I was in part successful with the mapping tool, alas it still tries to open
a connection

<openjpa:mappingtool action="buildSchema" schemaaction="createDB"
sqlfile="${basedir}/build/sql/create.sql">
	<config
propertiesFile="${basedir}/build/conf/META-INF/persistence.xml" />
	<classpath>
		<pathelement location="${basedir}/build/model" />
	</classpath>
</openjpa:mappingtool>

Regards,
Frank


RE: generate DDL script without database access

Posted by Michael Vorburger <mv...@odyssey-group.com>.
Hello,

Has anybody here managed to successfully run the mappingtool
"connection-less" in order to generate DDL script without database
access? How??

The initial message below says "if you put enough information into the
openjpa.jdbc.DBDictionary setting, then things should work." and "Re:
Using DDL generation in a Java EE environment?" post at
http://mail-archives.apache.org/mod_mbox/openjpa-dev/200704.mbox/%3C77F5
9D4E-8D97-46E5-961C-4D029B4B7228@apache.org%3E says you have to use a
-SchemaFactory file(empty-schema.xml), so I'm tried like this:

org.apache.openjpa.jdbc.meta.MappingTool -schemaAction build
-foreignKeys true -sql target/create.sql -ConnectionDriverName
com.sybase.jdbc3.jdbc.SybDriver -ConnectionURL
jdbc:sybase:Tds:SOMEHOST:123/SOMEDB?BE_AS_JDBC_COMPLIANT_AS_POSSIBLE=tru
e -ConnectionUserName SOMEUSER -ConnectionPassword SOMEPASS
-SchemaFactory file(empty-schema.xml)

with that empty-schema.xml containing only "<?xml version="1.0"
encoding="UTF-8"?><schemas/>", but you still get the
java.sql.SQLException from the JDBC Driver because it's trying to
connect anyways... I tried with "-schemaAction none" too, but that just
writes an empty (0 bytes) create.sql.  What other options are needed
(-record

It's definitely possible to create the schema in the XML format via e.g.
"mappingtool -schemaAction build -foreignKeys true -schemaFile
target/create.xml -ConnectionDriverName
com.sybase.jdbc3.jdbc.SybDriver", but when you try to run e.g.
"schematool -f target/create.sql target/create.xml -ConnectionDriverName
com.sybase.jdbc3.jdbc.SybDriver" it again tries to connect to a DB!

Looking at the code, the MappingTool.newSchemaTool(String action) does a
SchemaTool tool = new SchemaTool(_conf, action).  The SchemaTool
constructor always tries a _ds = conf.getDataSource2(null) which does a
test getConnection() deep inside JDBCConfigurationImpl()'s
getConnectionFactory's through a
DataSourceFactory.installDBDictionary().  I tried hacking that out, but
there is more direct JDBC calls later... did anybody manage to
successfully run the mappingtool "connection-less"?

The "Re: using mapping tool for DB2 offline" thread from 08.04.2008 is
about doing the same on DB2, where there seems to be a DB2-specific NPE
(that was fixed in OPENJPA-555), so I'm guessing some folks do manage to
generate DDL script without database access, but how??

Thanks.


-----Original Message-----
From: Frank Schwarz [mailto:frank.schwarz@gmx.de] 
Sent: jeudi, 13. mars 2008 15:11
To: users@openjpa.apache.org
Subject: Re: generate DDL script without database access

Hi Patrick,

thank you for your answer. The stack trace looks like this:

<openjpa-1.0.2-r420667:627158 fatal store error>
org.apache.openjpa.util.StoreException: Verbindung ist unterbrochen
   at
org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(Dat
aSourceFactory.java:234)
   at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(
JDBCConfigurationImpl.java:709)
   at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource(JDBCCon
figurationImpl.java:809)
   at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource2(JDBCCo
nfigurationImpl.java:816)
   at
org.apache.openjpa.jdbc.schema.SchemaTool.<init>(SchemaTool.java:127)
   at
org.apache.openjpa.jdbc.meta.MappingTool.newSchemaTool(MappingTool.java:
306)
   at
org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:486)
   at
org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:1069)
   at
org.apache.openjpa.jdbc.ant.MappingToolTask.executeOn(MappingToolTask.ja
va:197)
   at
org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
Caused by: org.h2.jdbc.JdbcSQLException: Verbindung ist unterbrochen
   ...
   at org.h2.Driver.connect(Driver.java:52)
   at
org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(Simp
leDriverDataSource.java:73)
   at
org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(Simp
leDriverDataSource.java:68)
   at
org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(Delegatin
gDataSource.java:113)
   at
org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(Decoratin
gDataSource.java:93)
   at
org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(Dat
aSourceFactory.java:226)
   ... 26 more

The connection is originally acquired in the constructor of
org.apache.openjpa.jdbc.schema.SchemaTool.

Kind regards,
Frank

Patrick Linskey schrieb:
> Hi,
>
> I believe that if you put enough information into the 
> openjpa.jdbc.DBDictionary setting, then things should work.
>
> Where are you seeing the connection come from? I.e., what's the 
> exception stack trace?
>
> -Patrick
>
> On Mon, Mar 10, 2008 at 3:08 AM, Frank Schwarz <fr...@gmx.de>
wrote:
>   
>> Hi,
>>
>>  is there a possibility to let OpenJPA create a SQL DDL script 
>> without  accessing the database? I would like to apply this script 
>> later on to an  empty database.
>>
>>  I was in part successful with the mapping tool, alas it still tries 
>> to open  a connection
>>
>>  <openjpa:mappingtool action="buildSchema" schemaaction="createDB"
>>  sqlfile="${basedir}/build/sql/create.sql">
>>         <config
>>  propertiesFile="${basedir}/build/conf/META-INF/persistence.xml" />
>>         <classpath>
>>                 <pathelement location="${basedir}/build/model" />
>>         </classpath>
>>  </openjpa:mappingtool>
>>
>>  Regards,
>>  Frank
>>
>>
>>     
>
>
>
>   


____________________________________________________________

� This email and any files transmitted with it are CONFIDENTIAL and intended
  solely for the use of the individual or entity to which they are addressed.
� Any unauthorized copying, disclosure, or distribution of the material within
  this email is strictly forbidden.
� Any views or opinions presented within this e-mail are solely those of the
  author and do not necessarily represent those of Odyssey Financial
Technologies SA unless otherwise specifically stated.
� An electronic message is not binding on its sender. Any message referring to
  a binding engagement must be confirmed in writing and duly signed.
� If you have received this email in error, please notify the sender immediately
  and delete the original.

Re: generate DDL script without database access

Posted by Frank Schwarz <fr...@gmx.de>.
Hi Patrick,

thank you for your answer. The stack trace looks like this:

<openjpa-1.0.2-r420667:627158 fatal store error> 
org.apache.openjpa.util.StoreException: Verbindung ist unterbrochen
   at 
org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:234)
   at 
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:709)
   at 
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource(JDBCConfigurationImpl.java:809)
   at 
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource2(JDBCConfigurationImpl.java:816)
   at org.apache.openjpa.jdbc.schema.SchemaTool.<init>(SchemaTool.java:127)
   at 
org.apache.openjpa.jdbc.meta.MappingTool.newSchemaTool(MappingTool.java:306)
   at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:486)
   at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:1069)
   at 
org.apache.openjpa.jdbc.ant.MappingToolTask.executeOn(MappingToolTask.java:197)
   at org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
Caused by: org.h2.jdbc.JdbcSQLException: Verbindung ist unterbrochen
   ...
   at org.h2.Driver.connect(Driver.java:52)
   at 
org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:73)
   at 
org.apache.openjpa.jdbc.schema.SimpleDriverDataSource.getConnection(SimpleDriverDataSource.java:68)
   at 
org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:113)
   at 
org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:93)
   at 
org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:226)
   ... 26 more

The connection is originally acquired in the constructor of 
org.apache.openjpa.jdbc.schema.SchemaTool.

Kind regards,
Frank

Patrick Linskey schrieb:
> Hi,
>
> I believe that if you put enough information into the
> openjpa.jdbc.DBDictionary setting, then things should work.
>
> Where are you seeing the connection come from? I.e., what's the
> exception stack trace?
>
> -Patrick
>
> On Mon, Mar 10, 2008 at 3:08 AM, Frank Schwarz <fr...@gmx.de> wrote:
>   
>> Hi,
>>
>>  is there a possibility to let OpenJPA create a SQL DDL script without
>>  accessing the database? I would like to apply this script later on to an
>>  empty database.
>>
>>  I was in part successful with the mapping tool, alas it still tries to open
>>  a connection
>>
>>  <openjpa:mappingtool action="buildSchema" schemaaction="createDB"
>>  sqlfile="${basedir}/build/sql/create.sql">
>>         <config
>>  propertiesFile="${basedir}/build/conf/META-INF/persistence.xml" />
>>         <classpath>
>>                 <pathelement location="${basedir}/build/model" />
>>         </classpath>
>>  </openjpa:mappingtool>
>>
>>  Regards,
>>  Frank
>>
>>
>>     
>
>
>
>   


Re: generate DDL script without database access

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

I believe that if you put enough information into the
openjpa.jdbc.DBDictionary setting, then things should work.

Where are you seeing the connection come from? I.e., what's the
exception stack trace?

-Patrick

On Mon, Mar 10, 2008 at 3:08 AM, Frank Schwarz <fr...@gmx.de> wrote:
> Hi,
>
>  is there a possibility to let OpenJPA create a SQL DDL script without
>  accessing the database? I would like to apply this script later on to an
>  empty database.
>
>  I was in part successful with the mapping tool, alas it still tries to open
>  a connection
>
>  <openjpa:mappingtool action="buildSchema" schemaaction="createDB"
>  sqlfile="${basedir}/build/sql/create.sql">
>         <config
>  propertiesFile="${basedir}/build/conf/META-INF/persistence.xml" />
>         <classpath>
>                 <pathelement location="${basedir}/build/model" />
>         </classpath>
>  </openjpa:mappingtool>
>
>  Regards,
>  Frank
>
>



-- 
Patrick Linskey
202 669 5907