Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How can I generate tables from entities?

Gerhard,

1) For your first issue where there are deprecation warnings, check the following
- are you using 2 or more persistence units in your persistence.xml?  I have 2 persistence units in my persistence.xml - I changed all 2 x 4 = 8 properties to get rid of warnings during preprocessing of both persistence units.
- otherwise verify that your orm.xml is not overriding properties.

For example...
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Direct_connection_.28RESOURCE_LOCAL.29_Persistence.xml

>Before:
            <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
            <property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
            <property name="eclipselink.jdbc.user" value="user"/>
            <property name="eclipselink.jdbc.password" value="pw"/>

>generates
[EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: 2009-06-09 09:23:48.156--ServerSession(18680399)--Thread(Thread[main,5,main])--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.

>After a change to
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
            <property name="javax.persistence.jdbc.user" value="user"/>
            <property name="javax.persistence.jdbc.password" value="pw"/>

>generates no more property warnings.


2) For your lack of DDL script output, check that you are using the following format.
both drop-and-create-tables and create-tables will generate a "dropDDL.jdbc" file.
The key is that you should use "eclipselink.application-location" and not the spec defined "javax.persistence.application-location" property yet.

>The following
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="both"/>
            <property name="eclipselink.create-ddl-jdbc-file-name" value="ddl.txt"/>     
            <property name="eclipselink.application-location" value="c:/opt"/>

>generates
dropDDL.jdbc
ddl.txt (with create table DDL entries)


3) Table generator within a program?
See the usage of the following class
 http://fisheye2.atlassian.com/browse/eclipselink/trunk/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java

by the class
http://fisheye2.atlassian.com/browse/eclipselink/trunk/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableCreator.java

using the method call
public void replaceTables(org.eclipse.persistence.sessions.DatabaseSession session)

from for example
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTest.java

Note: When you use table generation in this way outside of standard JPA properties and annotations - you will be using native API of EclipseLink.


thank you
/michael


Gerhard Kratz wrote:
Hello, Michael,

thank you very much for your fast and helpful response. Your unsigned persistence jar-file really did it, the table generator works fine now.

In my case, which is admittedly a very simple one, it is even possible to generate tables with
<property name="eclipselink.ddl-generation" value="create-tables" />

I tried to boil my entity declaration down to the absolute necessary, the result is attached.

Some further feedback:
1. I changed all the prefixes of the properties in persistence.xml to
javax.persistence as you recommended.
  But I'm still getting the follwing output lines:

[EL Info]: property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.

2. With the line
            <property name="javax.persistence.ddl-generation.output-mode" value="both"/>
I tried to prompt EclipseLink to output the DDL in a text file, as well, which I then couldn't find in the directory specified in the XML element
            <property name="javax.persistence.application-location" value="C:\JPA"/>

How can one call the table generator from within a program?

Let me say that I'm really impressed by your fast and effective support.

best regards

Gerhard


Michael O'Brien schrieb:
Gerhard,
    Your directory structure looks fine - specifically the position of persistence.xml off of META-INF is good.
    You may use the following EclipseLink JPA SE schema generation example as a reference.
    There are differences in my database url (which includes a valid schema - IE no "null" schema) and ddl generation properties that include dropping the tables before recreating them - on each run.

jdbc:oracle:thin:@127.0.0.1:1521:orcl
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/

    For point #6 where you get a signed jar exception after adding eclipselink to your project...
    - you can use the following unsigned persistence jar - I had the same issue when initially setting up Tomcat for SE persistence a couple days ago.

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/plugins/javax.persistence_unsigned_for_testing_1.0.0.jar

    - the deprecated jdbc properties are ok - just change to using javax.persistence prefixes for the future


    For point #7
    - I have specified my schema on the url
    - I have modified sequence generation on my entity from the original Dali entity source generation.
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/src/org/eclipse/persistence/example/jpa/server/business/Cell.java

    thank you
    /michael


Gerhard Kratz wrote:
Hello,

my e-mail client seems to have a line-feed aversion. What seems important to me with the directory structure is:
- that file persistence.xml seems to be in the right place, namely in the subdirectory META-INF
- a class file has been generated

best regards

Gerhard
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

-- 
Prof. Dr. Gerhard Kratz
Fachhochschule Frankfurt am Main
Fachbereich 2: Informatik und Ingenieurwissenschaften
Nibelungenplatz 1
60318 Frankfurt am Main
WWW: http://www.fh-frankfurt.de/~g_kratz
     http://bscw.fh-frankfurt.de

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top