Jpa and add creation table if they don't exist yet?

It seems that jpa is what makes me ask a lot of questions.

Adding this

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

my JPA application always creates tables at startup, which leads to exceptions if the tables already exist. I would like JPA to check if existing tables exist and if they did not create them, however I could not find the value for the property above that does this.

So, if I just turn it off, is there a way to tell JPA manually at some point in order to create all the tables?

Refresh here the exception I get

 Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tags' already exists Error Code: 1050 Call: CREATE TABLE tags (ID BIGINT AUTO_INCREMENT NOT NULL, NAME VARCHAR(255), OCCURRENCE INTEGER, PRIMARY KEY (ID)) 

MySQLSyntaxErrorException ?! Now that this is wrong,

+6
java orm jpa
source share
3 answers

According to http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#Java2DBSchemaGen toplink is not able to update outgoing tables, I'm not sure if I believe this anyway. You can configure toplink to create an sql script, which you then have to execute manually to create all the tables. File names and their location can be configured as follows:

 <property name="toplink.ddl-generation" value="create-tables"/> <property name="toplink.ddl-generation.output-mode" value="sql-script"/> <property name="toplink.create-ddl-jdbc-file-name" value="createDDL.sql"/> <property name="toplink.drop-ddl-jdbc-file-name" value="dropDDL.sql"/> <property name="toplink.application-location" value="/tmp"/> 
+5
source share

I would like [my] JPA [provider] to check if tables already exist and if they are not created, however I could not find the value for the property above that does this.

Strange, according to the TopLink Essentials documentation on the toplink.ddl-generation extension, create-table should leave the existing table unchanged:

Toplink JPA Extensions for Schema Generation

Indicate which data descriptor language (DDL) for which you want your JPA objects. To indicate the DDL of a generation target, see toplink.ddl-generation.output-mode .

Valid Values: oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider

If you use persistence outside the EJB container and would like to create DDL files without creating a table, optionally define the Java system property INTERACT_WITH_DB and set it to false .

+2
source share

Liquibase ( http://www.liquibase.org ) is good at this. It will take some time to fully use it, but I think it is worth the effort.

The Liquibase path is independent of the JPA persistence provider used. In fact, he is even an agnostic database.

0
source share

All Articles