JPA和toplink创建表是否不存在? [英] JPA and toplink create-table on if they don't already exist?
问题描述
看起来jpa会让我问很多问题.
Looks like jpa is something which makes me ask a lot of questions.
已添加此
<property name="toplink.ddl-generation" value="create-tables"/>
我的JPA应用程序始终在运行时创建表,如果表已经存在,则会导致异常.我希望JPA检查表是否已经存在,如果不创建表,但是我找不到上面可以执行此操作的属性的值.
my JPA application always creates tables when running, which results in exceptions in case the tables already exist. I would like JPA to check if the tables already exist and if not create them, however I could not find a value for the property above which does this.
因此,如果我只是将其关闭,是否有办法在某个时候手动告诉JPA创建所有表?
So if I just turn it off, is there a way to tell JPA manually at some point to create all the tables?
更新,这是我得到的异常
Update here's 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 ?!现在肯定是错误的
MySQLSyntaxErrorException?! Now that's wrong for sure
推荐答案
According to http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#Java2DBSchemaGen toplink does not have an option to update exiting tables, I'm not sure if I would trust it to do the right thing anyway. You could configure toplink to generate a sql script that you then would have to execute manually to create all tables. The filenames and location can be configured like this:
<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"/>
这篇关于JPA和toplink创建表是否不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!