Eclipselink更新现有表 [英] Eclipselink update existing tables

查看:118
本文介绍了Eclipselink更新现有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我弄错了,但我认为JPA能够更新现有的表(模型已更改添加列)但在我的情况下不起作用。

Maybe I got it wrong but i though that JPA was able to update an existing table (model changed adding a column) but is not working in my case.

我可以在日志中看到eclipselink试图创建它但失败因为它已经存在。而不是尝试更新以添加列。它继续前进。

I can see in the logs eclipselink attempting to create it but failing because it already exists. Instead of trying an update to add the column it keeps going.

<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jwrestling"/>
<property name="javax.persistence.jdbc.password" value="password"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
<property name="eclipselink.logging.level" value="INFO"/>

以下是更改的表格(在线栏目已添加)

And here's the table with the change (online column added)


[EL Warning]: 2010-05-31 14:39:06.044--ServerSession(16053322)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.0.v20100517-r7246): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'account' already exists
Error Code: 1050
Call: CREATE TABLE account (ID INTEGER NOT NULL, USERNAME VARCHAR(32) NOT NULL, SECURITY_KEY VARCHAR(255) NOT NULL, EMAIL VARCHAR(64) NOT NULL, STATUS VARCHAR(8) NOT NULL, TIMEDATE DATETIME NOT NULL, PASSWORD VARCHAR(255) NOT NULL, ONLINE TINYINT(1) default 0 NOT NULL, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE account (ID INTEGER NOT NULL, USERNAME VARCHAR(32) NOT NULL, SECURITY_KEY VARCHAR(255) NOT NULL, EMAIL VARCHAR(64) NOT NULL, STATUS VARCHAR(8) NOT NULL, TIMEDATE DATETIME NOT NULL, PASSWORD VARCHAR(255) NOT NULL, ONLINE TINYINT(1) default 0 NOT NULL, PRIMARY KEY (ID))")
[EL Warning]: 2010-05-31 14:39:06.074--ServerSession(16053322)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.0.v20100517-r7246): org.eclipse.persistence.exceptions.DatabaseException

在此之后继续以下。

我做错了什么或是个错误?

Am I doing something wrong or is a bug?

推荐答案

从EclipseLink 2.4开始,您可以在持久性单元的规范中使用它:

As of EclipseLink 2.4, you can use this in the specification of your persistence unit:

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

这篇关于Eclipselink更新现有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆