
Monday December 19, 2005
Pramod Gopinath's Weblog
Glassfish and Automatic Table Generation for out-of-container
Glassfish has the feature that would enable the user to
automatically generate the database schema for out-of-container
(javase) applications.
How to enable java2db for out-of-container case ?
For the EJB3. 0 application that would be run outside of the container
ensure that the persistence.xml file has the toplink.ddl-generation property
set to a value of "drop-and-create-tables" or "create-tables".
|
Property Name
|
Description
|
|
toplink.ddl-generation
|
Possible values of
“create-tables"/"drop-and-create-tables"/"none".
The default value is “none”.
|
|
toplink.create-ddl-jdbc-file-name
|
(Optional) Name of the create jdbc ddl file.
The default value is "createDDL.jdbc".
|
|
toplink.drop-ddl-jdbc-file-name
|
(Optional) Name of the drop jdbc ddl file.
The default value is "dropDDL.jdbc".
|
|
toplink.application-location
|
(Optional) The location where the ddl files have
to be written out.
The defaul value is "." i.e the current working directory
|
Below is an e.g of a persistence.xml for an out of container case
running against the Derby database
<?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" >
<persistence-unit name ="em"
>
<description>Basic javaSE application containing JSR 220 entity
beans</description>
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<properties>
<!-- JDBC connection
properties -->
<property name="toplink.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
<property
name="toplink.jdbc.url"
value="jdbc:derby://localhost:1527/testdb;retrieveMessagesFromServerOnGetMessage=true;create=true;"/>
<property name="toplink.jdbc.user"
value="APP"/>
<property name="toplink.jdbc.password"
value="APP"/>
<!--java2db properties -->
<property
name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
<class>entity.Customer</class>
<class>entity.Item</class>
<class>entity.Order</class>
</persistence-unit>
</persistence>
How to get the the jdbc ddl statements
written out into files but not create/drop the tables in the database ?
There could be a use case where you would be
interested to get the ddl statements associated with your application
written out into the files but not do the actual drop/create of the
entities in the database. In the javaSE environment when using
Glassfish you can achieve this by ensuring that the toplink.ddl-generation
feature is turned on in the persistence.xml file and additionally
defining a java
system property "INTERACT_WITH_DB". If you define this java system
property with the value of "false" then the tables would not be created
in the database, but the ddl files would be written out. This feature
is for the out-of-container case only.
Posted by pramodg
( Dec 19 2005, 04:30:18 PM PST )
Permalink
Trackback URL: http://blogs.sun.com/java2dbInGlassFish/entry/automatic_table_generation_feature_for
Posted by 59.95.111.218 on August 31, 2006 at 11:21 PM PDT #
Then, when I change the name of the generated table with the Table annotation on the entity using the full qualified name of that table ("mydb.PERSON") I don't get any trace but it doesn't drop anyway.
The persistence.xml is:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> <persistence-unit name="p"> <class>ar.com.qrt2.entities.Person</class> <properties> <property name="toplink.jdbc.driver" value="org.gjt.mm.mysql.Driver"/> <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/mydb"/> <property name="toplink.jdbc.user" value="mydb"/> <property name="toplink.jdbc.password" value="mydb"/> <property name="toplink.logging.level" value="INFO"/> <property name="toplink.ddl-generation" value="drop-and-create-tables"/> </properties> </persistence-unit> </persistence>Am I missing something? Do you have any idea ?
Regards,
Diego
Posted by Diego R. Mercado on January 22, 2007 at 02:44 PM PST #