Revert "Bug 441546 - Foreign Key attribute when used in JoinColumn generates wrong DDL statement."
due to the failures on TCK side
This reverts commit 57df5603e58c65b9b2bb501b734ccc14aae0063c.
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java
index 74221f6..af21597 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/tools/schemaframework/TableDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -19,8 +19,6 @@
* - 389090: JPA 2.1 DDL Generation Support (foreign key metadata support)
* 02/04/2013-2.5 Guy Pelletier
* - 389090: JPA 2.1 DDL Generation Support
- * 10/07/2017-2.7 Vikram Bhatia
- * - 441546: Foreign Key attribute when used in JoinColumn generates wrong DDL statement
*******************************************************************************/
package org.eclipse.persistence.tools.schemaframework;
@@ -1364,13 +1362,8 @@
* Set the foreign key constraints for this table.
*/
public void setUserDefinedForeignKeyConstraints(Map<String, ForeignKeyConstraint> foreignKeyConstraints) {
- for (ForeignKeyConstraint fkConstraint : foreignKeyConstraints.values()) {
- if (!fkConstraint.getSourceFields().isEmpty() && !fkConstraint.getTargetFields().isEmpty()) {
- hasUserDefinedForeignKeyConstraints = true;
- foreignKeyMap = foreignKeyConstraints;
- break;
- }
- }
+ foreignKeyMap = foreignKeyConstraints;
+ hasUserDefinedForeignKeyConstraints = true;
}
/**
diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/persistence.xml
index ab9ccf2..7057013 100644
--- a/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/persistence.xml
+++ b/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/persistence.xml
@@ -73,8 +73,6 @@
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Athlete</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Race</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Coach</class>
- <class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Driver</class>
- <class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Vehicle</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.AccomplishmentConverter</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.AgeConverter</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.DateConverter</class>
diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/server/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/server/persistence.xml
index 3cda31c..190ad8e 100644
--- a/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/server/persistence.xml
+++ b/jpa/eclipselink.jpa.test/resource/eclipselink-jpa21-model/server/persistence.xml
@@ -80,8 +80,6 @@
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Athlete</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Race</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Coach</class>
- <class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Driver</class>
- <class>org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Vehicle</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.AccomplishmentConverter</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.AgeConverter</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.converters.DateConverter</class>
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Driver.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Driver.java
deleted file mode 100644
index ae7cc0a..0000000
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Driver.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * 07/07/2017-2.7 Vikram Bhatia
- * - 441546: Foreign Key attribute when used in JoinColumn generates wrong DDL statement
- ******************************************************************************/
-package org.eclipse.persistence.testing.models.jpa21.advanced.ddl;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "JPA21_DDL_DRIVER")
-public class Driver {
- @Id
- @Column(name = "NAME")
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-}
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Vehicle.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Vehicle.java
deleted file mode 100644
index c5498ff..0000000
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa21/advanced/ddl/Vehicle.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * 07/07/2017-2.7 Vikram Bhatia
- * - 441546: Foreign Key attribute when used in JoinColumn generates wrong DDL statement
- ******************************************************************************/
-package org.eclipse.persistence.testing.models.jpa21.advanced.ddl;
-
-import javax.persistence.Entity;
-import javax.persistence.ForeignKey;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity
-@Table(name="JPA21_DDL_VEHICLE")
-public class Vehicle {
-
- @Id
- private String vnum;
-
- @ManyToOne
- @JoinColumn(name="LAST",foreignKey=@ForeignKey(name="FKv2d"))
- private Driver driver;
-
- public String getVnum() {
- return vnum;
- }
- public void setVnum(String vnum) {
- this.vnum = vnum;
- }
- public Driver getDriver() {
- return driver;
- }
- public void setDriver(Driver driver) {
- this.driver = driver;
- }
-}
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/ForeignKeyTestSuite.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/ForeignKeyTestSuite.java
index 9e7697d..dcb2677 100644
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/ForeignKeyTestSuite.java
+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/ForeignKeyTestSuite.java
@@ -27,7 +27,6 @@
import javax.persistence.EntityManager;
import org.eclipse.persistence.descriptors.ClassDescriptor;
-import org.eclipse.persistence.exceptions.DatabaseException;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy;
import org.eclipse.persistence.mappings.DirectCollectionMapping;
@@ -42,7 +41,6 @@
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Coach;
-import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Driver;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Organizer;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Race;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Responsibility;
@@ -51,7 +49,7 @@
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.RunnerStatus;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Shoe;
import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Sprinter;
-import org.eclipse.persistence.testing.models.jpa21.advanced.ddl.Vehicle;
+
import org.eclipse.persistence.testing.models.jpa21.advanced.enums.Health;
import org.eclipse.persistence.testing.models.jpa21.advanced.enums.Level;
import org.eclipse.persistence.testing.models.jpa21.advanced.enums.RunningStatus;
@@ -97,7 +95,6 @@
suite.addTest(new ForeignKeyTestSuite("testElementCollectionForeignKeys"));
suite.addTest(new ForeignKeyTestSuite("testReadAndWriteDDLObjects"));
- suite.addTest(new ForeignKeyTestSuite("testBug441546"));
return suite;
@@ -271,63 +268,4 @@
closeEntityManager(em);
}
}
-
- /**
- * Tests a many to one foreign key setting with null foreign key definition.
- */
- public void testBug441546() {
- EntityManager em = createEntityManager();
-
- try {
- beginTransaction(em);
-
- Driver driver = new Driver();
- driver.setName("Bob");
-
- Vehicle vehicle = new Vehicle();
- vehicle.setVnum("1A467");
- vehicle.setDriver(driver);
-
- em.persist(driver);
- em.persist(vehicle);
- commitTransaction(em);
-
- } catch (RuntimeException e) {
- if (isTransactionActive(em)){
- rollbackTransaction(em);
- }
-
- throw e;
- } finally {
- closeEntityManager(em);
- }
-
- em = createEntityManager();
- try {
- // Try Deleting Driver with constraint
- beginTransaction(em);
-
- Driver d2 = em.find(Driver.class, "Bob");
- em.remove(d2);
-
- commitTransaction(em);
- fail("Foreign Key constraint is not defined in database on table.");
-
- } catch (RuntimeException e) {
- if (isTransactionActive(em)){
- rollbackTransaction(em);
- }
-
- Throwable cause = e.getCause();
-
- if (cause instanceof DatabaseException) {
- assertTrue("Error Deleting row with constraint with different error.", cause.getCause() instanceof java.sql.SQLIntegrityConstraintViolationException);
- } else {
- throw e;
- }
-
- } finally {
- closeEntityManager(em);
- }
- }
}