From 4e527d0f3ed35a2eb1daf8e5f85450478d5e9a2b Mon Sep 17 00:00:00 2001 From: Andrew Clemons Date: Tue, 29 Oct 2013 07:48:55 +1300 Subject: [PATCH] HHH-8228 - enable foreign keys in HANA dialects by defaulting to 'ON UPDATE CASCADE' --- .../dialect/AbstractHANADialect.java | 28 ++++++------------- .../dialect/HANARowStoreDialect.java | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index 41cf9f183f..6975d924f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -63,12 +63,10 @@ import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; /** * An abstract base class for HANA dialects.
* SAP HANA Reference
- * - * NOTE: This dialect is currently configured to not create foreign keys by - * returning the empty string from {@link #getAddForeignKeyConstraintString} since they currently have caveats compared - * to other databases. This does not - * affect using this dialect with your own DDL scripts which use foreign keys. - * + * + * NOTE: This dialect is currently configured to create foreign keys with + * on update cascade. + * * @author Andrew Clemons */ public abstract class AbstractHANADialect extends Dialect { @@ -574,14 +572,6 @@ public abstract class AbstractHANADialect extends Dialect { return false; } - @Override - public boolean supportsCascadeDelete() { - // HANA does support cascade deletes, but since we have (temporarily) overridden the foreign key support, - // this should also be false. - // TODO: Enable once FK support is solidified and getAddForeignKeyConstraintString is corrected. - return false; - } - @Override public ScrollMode defaultScrollMode() { return ScrollMode.FORWARD_ONLY; @@ -673,14 +663,14 @@ public abstract class AbstractHANADialect extends Dialect { } /** - * Currently disabling foreign key creation when using Hibernate's auto-ddl - * feature. HANA does allow creating foreign keys, but currently they do not always - * behave as expected. + * The default behaviour for 'on update restrict' on HANA is currently + * to not allow any updates to any column of a row if the row has a + * foreign key. Make the default for foreign keys have 'on update cascade' + * to work around the issue. */ @Override public String getAddForeignKeyConstraintString(final String constraintName, final String[] foreignKey, final String referencedTable, final String[] primaryKey, final boolean referencesPrimaryKey) { - // TODO: Re-evaluate in a later HANA release where, hopefully, this has been solidified. - return ""; + return super.getAddForeignKeyConstraintString(constraintName, foreignKey, referencedTable, primaryKey, referencesPrimaryKey) + " on update cascade"; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java index c17b6eb564..7aa5883e5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java @@ -31,7 +31,7 @@ package org.hibernate.dialect; * @author Andrew Clemons */ public class HANARowStoreDialect extends AbstractHANADialect { - + // Even though it's currently pointless, provide this structure in case HANA row store merits additional // differences in the future.