我正在使用Eclipselink 2.5.1,我遇到的问题是,当我运行Project-> JPA工具 - >创建表格时,不会发生表格更新...虽然我有
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
在我的peristence.xml中(生成输出模式=数据库)。
我有一个已经存在的数据库表地址是从JpaEntity 地址创建的。 创建表后,我想添加另一个名为 addressType 的列,其类型为 AddressType ,这是一个枚举。
在我的JpaEntity 地址 Eclipse抱怨在表地址中找不到 addressType 列。
从实体重新创建表格并不是我想要的。该列不会添加到现有表结构中。我错过了什么?
运行项目 - &gt; JPA工具 - &gt;从实体创建表...提供以下输出:
[EL Config]: metadata: The alias name for the entity class [class com.tsystems.ikt.service.jpaParking.model.Address] is being defaulted to: Address.
[EL Config]: metadata: The column name for element [region] is being defaulted to: REGION.
[EL Config]: metadata: The column name for element [street] is being defaulted to: STREET.
[EL Config]: metadata: The column name for element [zipCode] is being defaulted to: ZIPCODE.
[EL Config]: metadata: The column name for element [streetNumber] is being defaulted to: STREETNUMBER.
[EL Config]: metadata: The column name for element [addressType] is being defaulted to: ADDRESSTYPE.
[EL Config]: metadata: The column name for element [addressId] is being defaulted to: ADDRESSID.
[EL Config]: metadata: The column name for element [city] is being defaulted to: CITY.
[EL Config]: metadata: The column name for element [country] is being defaulted to: COUNTRY.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Fine]: connection: Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE entrances
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'addresses' already exists
Error Code: 1050
Call: CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))
Query: DataModifyQuery(sql="CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))")
为什么Eclipselinkt尝试删除并重新创建表地址,尽管我说 create-or-extend-tables ?
答案 0 :(得分:0)
“eclipselink.ddl-generation”是EclipseLink运行时属性,在部署您的peristence单元时会查看该属性,但您没有运行/部署持久性单元。相反,您正在执行Eclipse命令以从实体创建表。 Eclipse使用EclipseLink,但会传递自己的属性,以确保在指向的数据库上创建表。这里的设置如下所述: https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks007.htm
如果您想让EclipseLink扩展您的表,只需运行您的应用程序。