Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » how to write DDL sql for create table in Eclipselink JPA
how to write DDL sql for create table in Eclipselink JPA [message #1773857] Thu, 05 October 2017 13:17 Go to next message
Maofeng Li is currently offline Maofeng LiFriend
Messages: 1
Registered: October 2017
Junior Member
I want to use JPA(eclipselink2.5, jpa2.1, glassfish4.0) to create tables automatically by persistence.xml setting, but i found each sql must write in a single line and there must not have a semicolon just like below:

The first situation dose not work(because the code is not in a single line manner)

create table student(
   id Integer, 
   name varchar2(50)
)    


The Second situation dose not work neither(because a semicolon added at the end of the sql sentence):

create table school(id Integer, name varchar2(50));
create table student(id Integer, name varchar2(50),school_id Integer);


The SQLs listed below are correct(which have not semicolons in each line end, and every line is a standalone sql),but create a table SQL in a single line should not be friendly to read and maintain. Is anybody know a better way to resolve this issue?

create table school(id Integer, name varchar2(50))
create table student(id Integer, name varchar2(50),school_id Integer)


Re: how to write DDL sql for create table in Eclipselink JPA [message #1774650 is a reply to message #1773857] Wed, 18 October 2017 10:32 Go to previous message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 144
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi Maofeng

did you already try to generate the ddl files automatically by eclipselink? There exist PersistenceUnitProperties to do that (it also adapts the sql for the used database platform.
Try adding
property key: PersistenceUnitProperties.DDL_GENERATION
property value: PersistenceUnitProperties.CREATE_OR_EXTEND
to generate
property key: PersistenceUnitProperties.DDL_GENERATION_MODE
property value: PersistenceUnitProperties.DDL_SQL_SCRIPT_GENERATION
as sql script
See documentation: https://www.eclipse.org/eclipselink/api/2.5/org/eclipse/persistence/config/PersistenceUnitProperties.html
Previous Topic:complex merge fails with IntegrityConstraintException <SOLVED>
Next Topic:Cache Coordination not Working properly
Goto Forum:
  


Current Time: Fri Dec 15 16:06:38 GMT 2017

Powered by FUDForum. Page generated in 0.02290 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software