2

I use eclipselink.ddl-generation.output-mode=database to generate the database schema. Can the generated SQL use character length semantics for generation of varchar2 fields? Enhance generated DDL of EclipseLink seems to related and an answer to this question would probably solve this.

Drunix
  • 3,313
  • 8
  • 28
  • 50

1 Answers1

1

There are two ways to change the SQL that is generated. The first would be to change the target database platform and is EclipseLink specific. This allows you to pick any database platform class, and you could override your database's platform to use what ever type definition you wanted, but this would be generic - ie all Strings would use a Varchar(255).

Another way is to change it using JPA annotations. The @Column annotation allows specifying the length which may or may not be used for DDL, as well as defining the columnDefinition which is used for DDL. Something like @Column(name="..", columndefinition="Varchar2(255) NOT NULL")

Chris
  • 20,138
  • 2
  • 29
  • 43
  • I would like to avoid columndefinition in @Column annotations because this makes the definition database specific. If the platform class would override printFieldTypeSize, this would also solve the problem with all column definitions being the same, wouldn't it? – Drunix Jan 13 '16 at 15:19
  • You should be able to use the length of the column annotation. The platform's buildFieldTypes method is where the String->Varchar2 mapping and default size is set. You could probably do the same with a customizer to just change or add the appropriate FieldTypeDefinition to the map for the String class with session.getPlatform().getFieldTypes().put(String.class, new FieldTypeDefinition("VARCHAR2", NEW_DEFAULT_SIZE));. Customizers are shown here http://www.eclipse.org/eclipselink/documentation/2.5/dbws/creating_dbws_services002.htm – Chris Jan 13 '16 at 17:59