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 13:23:27 UTC
Can somebody tell me how to generate DDLs
Hi
I am trying to execute the following command.
************
C:\temp\junk\WEB-INF\classes\samples\jpa>java
org.apache.openjpa.jdbc.meta.MappingTool -sql DDL.sql
-ConnectionDriverName com.ibm.db2.jcc.DB2Driver Product.java
I get the following output:
--------------------------------------
Some product derivations are being skipped. For information about
product derivation status, run:
java org.apache.openjpa.lib.conf.ProductDerivations
120 INFO [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.DB2Dictionary".
Exception in thread "main" <openjpa-1.0.0-r5715:6560 fatal user error>
org.apache.openjpa.util.MetaDataException: MetaDataFactory could not
be configured (conf.newMetaDataFactoryInstance() returned null). This
might mean that no configuration properties were found. Ensure that
you have a META-INF/persistence.xml file, that it is available in your
classpath, or that the properties file you are using for configuration
is available. If you are using Ant, please see the <properties> or
<propertiesFile> attributes of the task's nested <config> element.
This can also occur if your OpenJPA distribution jars are corrupt, or
if your security policy is overly strict.
at org.apache.openjpa.meta.MetaDataRepository.initializeMetaDataFactory(MetaDataRepository.java:1520)
at org.apache.openjpa.meta.MetaDataRepository.endConfiguration(MetaDataRepository.java:1513)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1218)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:467)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:392)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:102)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:82)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:857)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:852)
at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:1009)
at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:980)
at org.apache.openjpa.jdbc.meta.MappingTool.main(MappingTool.java:921)
Can somebody tell me how to generate DDLs without connecting to the
database?? or with a connection to database??
Thanks
Phani
Re: Can somebody tell me how to generate DDLs
Posted by Phani Madgula <ph...@gmail.com>.
Thanks for info...I am able to generate the DDLs into a file. The
MappingTool requires database connection though.
Thanks
Phani
On 12/17/08, Michael Dick <mi...@gmail.com> wrote:
> Hi all,
>
> If a connection to the database is not available (or desired) you can try
> something like this.
>
> Assumptions :
> 1. target/classes contains your compiled classes
> 2. target/classes/META-INF/persistence.xml exists and includes a list of
> your entities
> 3. ${OPENJPA_LOC} contains openjpa.jar
> 4. ${OPENJPA_LOC}/lib includes the dependencies from our binary archive
> 5. The example uses derby, you can use db2, oracle or any of the
> DBDictionary classes included with OpenJPA
>
> $ export CLASSPATH=target/classes:${OPENJPA_LOC}/openjpa.jar
> $ java -cp ${CLASSPATH} -Djava.ext.dirs=${OPENJPA_LOC}/lib
> org.apache.openjpa.jdbc.meta.MappingTool -sql temp.ddl -sa build
> -DBDictionary derby
>
> This will generate temp.ddl with the assumption that none of the tables
> exist.
>
> You can do something similar in ant with syntax similar to this :
> <taskdef name="mapping"
> classname="org.apache.openjpa.jdbc.ant.MappingToolTask"
> classpathref="openjpa.cp"/>
> . . .
> <mapping sqlFile="${classes.location}/temp.ddl" schemaAction="build">
> <config dbdictionary="derby"/>
> </mapping>
>
> Hope this helps,
> -mike
>
> On Tue, Dec 16, 2008 at 2:31 PM, Pinaki Poddar <pp...@apache.org> wrote:
>
>>
>> $ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
>> persistence.xml
>>
>> classpath should have
>> a) openjpa libraries
>> b) a directory X such that X/META-INF/persistence.xml exists
>>
>> persistence.xml should declare the classes you want to generate DDL for in
>> <class> clause.
>> AFAIR, there were some issues with generating DDL without a database
>> connection. So specify a database configuration in persistence.xml also.
>>
>> If you have many persistence unit defined in persistence.xml but want only
>> a
>> specific persistence unit (say Y) to be processed then append it as
>> follows
>>
>> $ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
>> persistence.xml#Y
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Can-somebody-tell-me-how-to-generate-DDLs-tp1662488p1664781.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
>
Re: Can somebody tell me how to generate DDLs
Posted by Michael Dick <mi...@gmail.com>.
Hi all,
If a connection to the database is not available (or desired) you can try
something like this.
Assumptions :
1. target/classes contains your compiled classes
2. target/classes/META-INF/persistence.xml exists and includes a list of
your entities
3. ${OPENJPA_LOC} contains openjpa.jar
4. ${OPENJPA_LOC}/lib includes the dependencies from our binary archive
5. The example uses derby, you can use db2, oracle or any of the
DBDictionary classes included with OpenJPA
$ export CLASSPATH=target/classes:${OPENJPA_LOC}/openjpa.jar
$ java -cp ${CLASSPATH} -Djava.ext.dirs=${OPENJPA_LOC}/lib
org.apache.openjpa.jdbc.meta.MappingTool -sql temp.ddl -sa build
-DBDictionary derby
This will generate temp.ddl with the assumption that none of the tables
exist.
You can do something similar in ant with syntax similar to this :
<taskdef name="mapping"
classname="org.apache.openjpa.jdbc.ant.MappingToolTask"
classpathref="openjpa.cp"/>
. . .
<mapping sqlFile="${classes.location}/temp.ddl" schemaAction="build">
<config dbdictionary="derby"/>
</mapping>
Hope this helps,
-mike
On Tue, Dec 16, 2008 at 2:31 PM, Pinaki Poddar <pp...@apache.org> wrote:
>
> $ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
> persistence.xml
>
> classpath should have
> a) openjpa libraries
> b) a directory X such that X/META-INF/persistence.xml exists
>
> persistence.xml should declare the classes you want to generate DDL for in
> <class> clause.
> AFAIR, there were some issues with generating DDL without a database
> connection. So specify a database configuration in persistence.xml also.
>
> If you have many persistence unit defined in persistence.xml but want only
> a
> specific persistence unit (say Y) to be processed then append it as follows
>
> $ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
> persistence.xml#Y
>
> --
> View this message in context:
> http://n2.nabble.com/Can-somebody-tell-me-how-to-generate-DDLs-tp1662488p1664781.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>
Re: Can somebody tell me how to generate DDLs
Posted by Pinaki Poddar <pp...@apache.org>.
$ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
persistence.xml
classpath should have
a) openjpa libraries
b) a directory X such that X/META-INF/persistence.xml exists
persistence.xml should declare the classes you want to generate DDL for in
<class> clause.
AFAIR, there were some issues with generating DDL without a database
connection. So specify a database configuration in persistence.xml also.
If you have many persistence unit defined in persistence.xml but want only a
specific persistence unit (say Y) to be processed then append it as follows
$ java org.apache.openjpa.jdbc.meta.MappingTool -sql test.ddl -p
persistence.xml#Y
--
View this message in context: http://n2.nabble.com/Can-somebody-tell-me-how-to-generate-DDLs-tp1662488p1664781.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.