Pergunta

i want to write query that create or alter table and run it any relational database (which supports JDBC) without modification. for example "create table employee( name varchar(250), personalNo varchar(245) )" can JPA run it underlying DB? is there any other method for this?

Foi útil?

Solução

You can configure your persistence.xml file to "create" the database tables during the deployment time, based on annotations made in the entity classes. This option generates a DDL (Data Definition Language) file that is processed by the JPA framework to generate the tables.

In JPA use the following property to trigger the table generation:

 <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
 </properties>

If you need to drop and recreate the table during each deploy you can use:

   <properties>
       <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
   </properties>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top