From 1a4b43720c620d2f6e3638776d854be7b815f6b6 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 5 Feb 2014 16:04:12 -0800 Subject: [PATCH] HHH-8897 : Add support for key-many-to-one on-delete="cascade" --- .../hibernate/metamodel/internal/Binder.java | 27 +++++++++---------- .../metamodel/internal/ForeignKeyHelper.java | 6 ++++- ...ociationRelationalBindingResolverImpl.java | 7 +++-- ...ociationRelationalBindingResolverImpl.java | 10 +++---- ...pedByPluralAttributeElementSourceImpl.java | 5 ++++ ...oManyPluralAttributeElementSourceImpl.java | 5 ++++ .../PluralAttributeKeySourceImpl.java | 10 +++---- .../annotations/ToOneAttributeSourceImpl.java | 5 ++++ .../ToOneMappedByAttributeSourceImpl.java | 5 ++++ .../source/hbm/KeyManyToOneSourceImpl.java | 5 ++++ ...oManyPluralAttributeElementSourceImpl.java | 5 ++++ .../hbm/ManyToOneAttributeSourceImpl.java | 5 ++++ .../hbm/OneToOneAttributeSourceImpl.java | 5 ++++ .../hbm/PluralAttributeKeySourceImpl.java | 6 ++--- .../source/ForeignKeyContributingSource.java | 8 ++++++ .../spi/source/PluralAttributeKeySource.java | 2 +- .../org/hibernate/hibernate-mapping-4.0.xsd | 1 + .../SessionFactorySerializationTest.java | 3 +++ .../test/hql/BulkManipulationTest.java | 3 +-- .../IdentifierPropertyReferencesTest.java | 1 - .../test/immutable/ImmutableTest.java | 24 ++++++++++++++--- .../component/EagerKeyManyToOneTest.java | 2 -- .../bidir/component/LazyKeyManyToOneTest.java | 2 -- .../bidir/embedded/KeyManyToOneTest.java | 2 -- .../KeyManyToOneCascadeDeleteTest.java | 2 -- .../KeyManyToOneCascadeDeleteTest.java | 2 -- .../plans/LoadPlanStructureAssertionTest.java | 3 --- ...atedCompositeIdResultSetProcessorTest.java | 2 -- .../walking/KeyManyToOneWalkingTest.java | 2 -- .../onetoone/formula/OneToOneFormulaTest.java | 2 +- .../junit4/BaseCoreFunctionalTestCase.java | 5 +--- 31 files changed, 110 insertions(+), 62 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index 7d9c07878f..5e98bfcdd3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -838,11 +838,11 @@ public class Binder implements HelperContext { table, joinRelationalValueBindings, foreignKeyHelper.determineForeignKeyTargetTable( superEntityBinding, subclassEntitySource ), - targetColumns + targetColumns, + subclassEntitySource.isCascadeDeleteEnabled() ); if ( subclassEntitySource.isCascadeDeleteEnabled() ) { - foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); entityBinding.setCascadeDeleteEnabled( true ); } } @@ -1256,20 +1256,19 @@ public class Binder implements HelperContext { table, joinRelationalValueBindings, foreignKeyHelper.determineForeignKeyTargetTable( entityBinding, secondaryTableSource ), - targetColumns + targetColumns, + secondaryTableSource.isCascadeDeleteEnabled() ); SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey ); - if(secondaryTableSource.getFetchStyle()!=null) - secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() ); + if ( secondaryTableSource.getFetchStyle()!=null ) { + secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() ); + } secondaryTable.setInverse( secondaryTableSource.isInverse() ); secondaryTable.setOptional( secondaryTableSource.isOptional() ); secondaryTable.setCascadeDeleteEnabled( secondaryTableSource.isCascadeDeleteEnabled() ); secondaryTable.setCustomDelete( secondaryTableSource.getCustomSqlDelete() ); secondaryTable.setCustomInsert( secondaryTableSource.getCustomSqlInsert() ); secondaryTable.setCustomUpdate( secondaryTableSource.getCustomSqlUpdate() ); - if ( secondaryTable.isCascadeDeleteEnabled() ) { - foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); - } entityBinding.addSecondaryTable( secondaryTable ); metadata.addSecondaryTable( secondaryTable ); } @@ -1334,7 +1333,8 @@ public class Binder implements HelperContext { ownerTable, extractColumnsFromRelationalValueBindings( ownerAssociationAttributeBinding.getRelationalValueBindings() ), entityBinding.getPrimaryTable(), - targetColumns + targetColumns, + attributeSource.isCascadeDeleteEnabled() ); if ( foreignKey == null ) { throw new AssertionFailure( "Foreign key not found; should have been defined by owner side of association." ); @@ -1348,9 +1348,6 @@ public class Binder implements HelperContext { secondaryTable.setCustomDelete( ownerSecondaryTable.getCustomDelete() ); secondaryTable.setCustomInsert( ownerSecondaryTable.getCustomInsert() ); secondaryTable.setCustomUpdate( ownerSecondaryTable.getCustomUpdate() ); - if ( secondaryTable.isCascadeDeleteEnabled() ) { - foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); - } entityBinding.addSecondaryTable( secondaryTable ); metadata.addSecondaryTable( secondaryTable ); } @@ -1428,13 +1425,15 @@ public class Binder implements HelperContext { final TableSpecification sourceTable, final List sourceRelationalValueBindings, final TableSpecification targetTable, - final List targetColumns) { + final List targetColumns, + boolean isCascadeDeleteEnabled) { return foreignKeyHelper.locateOrCreateForeignKey( foreignKeyName, sourceTable, extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ), targetTable, - targetColumns + targetColumns, + isCascadeDeleteEnabled ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ForeignKeyHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ForeignKeyHelper.java index d21e001fbe..0bc26c1fef 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ForeignKeyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/ForeignKeyHelper.java @@ -158,7 +158,8 @@ public class ForeignKeyHelper { final TableSpecification sourceTable, final List sourceColumns, final TableSpecification targetTable, - final List targetColumns) { + final List targetColumns, + boolean isCascadeDeleteEnabled) { final String foreignKeyName = helperContext.relationalIdentifierHelper().normalizeDatabaseIdentifier( explicitForeignKeyName, new ForeignKeyNamingStrategyHelper( sourceTable, sourceColumns, targetTable, targetColumns ) ); @@ -169,6 +170,9 @@ public class ForeignKeyHelper { foreignKey = sourceTable.createForeignKey( targetTable, foreignKeyName ); bindForeignKeyColumns( foreignKey, sourceTable, sourceColumns, targetTable, targetColumns ); } + if ( isCascadeDeleteEnabled ) { + foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); + } return foreignKey; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java index 1e10ccb64a..85761703cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/MappedByAssociationRelationalBindingResolverImpl.java @@ -103,7 +103,8 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa sourceTable, sourceColumns, targetTable, - targetColumns + targetColumns, + attributeSource.isCascadeDeleteEnabled() ); } @@ -270,7 +271,9 @@ public class MappedByAssociationRelationalBindingResolverImpl implements Associa (ManyToManyPluralAttributeElementBinding) pluralOwnerAttributeBinding.getPluralAttributeElementBinding(); foreignKey = ownerElementBinding.getForeignKey(); } - foreignKey.setDeleteRule( attributeSource.getKeySource().getOnDeleteAction() ); + if ( attributeSource.getKeySource().isCascadeDeleteEnabled() ) { + foreignKey.setDeleteRule( ForeignKey.ReferentialAction.CASCADE ); + } return foreignKey; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java index 77ddd77fc5..d15d799655 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/resolver/StandardAssociationRelationalBindingResolverImpl.java @@ -133,7 +133,8 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa sourceTable, sourceColumns, targetTable, - targetColumns + targetColumns, + attributeSource.isCascadeDeleteEnabled() ); } @@ -334,15 +335,13 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa referencedEntityBinding, keySource ); - ForeignKey foreignKey = locateOrCreateForeignKey( + return locateOrCreateForeignKey( keySource, referencedEntityBinding, collectionTable, sourceRelationalValueBindings, targetColumns ); - foreignKey.setDeleteRule( keySource.getOnDeleteAction() ); - return foreignKey; } @Override @@ -392,7 +391,8 @@ public class StandardAssociationRelationalBindingResolverImpl implements Associa sourceTable, extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ), targetTable, - targetColumns + targetColumns, + foreignKeyContributingSource.isCascadeDeleteEnabled() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java index d3be718e2e..4f6bc17655 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyMappedByPluralAttributeElementSourceImpl.java @@ -25,6 +25,11 @@ public class ManyToManyMappedByPluralAttributeElementSourceImpl public String getExplicitForeignKeyName() { throw new UnsupportedOperationException( "Not supported for attributes with mappedBy specified." ); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { throw new UnsupportedOperationException( "Not supported for attributes with mappedBy specified." ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyPluralAttributeElementSourceImpl.java index f4f34e2a0d..37b11b7472 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToManyPluralAttributeElementSourceImpl.java @@ -77,6 +77,11 @@ public class ManyToManyPluralAttributeElementSourceImpl return pluralAssociationAttribute().getInverseForeignKeyName(); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { boolean hasReferencedColumn = false; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java index ac48b30f1a..2a11d56e23 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java @@ -31,7 +31,6 @@ import org.hibernate.annotations.OnDeleteAction; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.attribute.Column; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; -import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.PluralAttributeKeySource; @@ -43,16 +42,15 @@ import org.hibernate.metamodel.spi.source.RelationalValueSource; */ public class PluralAttributeKeySourceImpl implements PluralAttributeKeySource { private final PluralAssociationAttribute attribute; - private final ForeignKey.ReferentialAction deleteAction; + private final boolean isCascadeDeleteEnabled; public PluralAttributeKeySourceImpl(PluralAssociationAttribute attribute) { this.attribute = attribute; - this.deleteAction = attribute.getOnDeleteAction() == OnDeleteAction.CASCADE - ? ForeignKey.ReferentialAction.CASCADE : ForeignKey.ReferentialAction.NO_ACTION; + this.isCascadeDeleteEnabled = attribute.getOnDeleteAction() == OnDeleteAction.CASCADE; } @Override - public ForeignKey.ReferentialAction getOnDeleteAction() { - return deleteAction; + public boolean isCascadeDeleteEnabled() { + return isCascadeDeleteEnabled; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java index fb609cc8af..654a35dcfc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java @@ -254,6 +254,11 @@ public class ToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl i return null; } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + public class AnnotationJoinColumnResolutionDelegate implements ForeignKeyContributingSource.JoinColumnResolutionDelegate { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneMappedByAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneMappedByAttributeSourceImpl.java index 39dbef9ea1..df1763bf4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneMappedByAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneMappedByAttributeSourceImpl.java @@ -107,6 +107,11 @@ public class ToOneMappedByAttributeSourceImpl extends AbstractToOneAttributeSour throw new UnsupportedOperationException( "Not supported for a \"mappedBy\" association." ); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { throw new UnsupportedOperationException( "Not supported for a \"mappedBy\" association." ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/KeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/KeyManyToOneSourceImpl.java index 1d31da7aaf..cd18bcf3dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/KeyManyToOneSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/KeyManyToOneSourceImpl.java @@ -197,4 +197,9 @@ class KeyManyToOneSourceImpl public String getExplicitForeignKeyName() { return keyManyToOneElement.getForeignKey(); } + + @Override + public boolean isCascadeDeleteEnabled() { + return "cascade".equals( keyManyToOneElement.getOnDelete().value() ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java index 18ab297d3f..2d1124e313 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java @@ -149,6 +149,11 @@ public class ManyToManyPluralAttributeElementSourceImpl return manyToManyElement.getForeignKey(); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { return manyToManyElement.getPropertyRef() == null diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java index 4b22da025d..131afc6f14 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java @@ -196,6 +196,11 @@ class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { return manyToOneElement.getForeignKey(); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public ForeignKeyDirection getForeignKeyDirection() { return ForeignKeyDirection.TO_PARENT; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java index 5c797677c7..3223bda2a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToOneAttributeSourceImpl.java @@ -192,6 +192,11 @@ class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { return oneToOneElement.getForeignKey(); } + @Override + public boolean isCascadeDeleteEnabled() { + return false; + } + @Override public ForeignKeyDirection getForeignKeyDirection() { return oneToOneElement.isConstrained() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/PluralAttributeKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/PluralAttributeKeySourceImpl.java index 3ca2b01bdf..108ba2fa4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/PluralAttributeKeySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/PluralAttributeKeySourceImpl.java @@ -110,10 +110,8 @@ public class PluralAttributeKeySourceImpl } @Override - public ForeignKey.ReferentialAction getOnDeleteAction() { - return "cascade".equals( keyElement.getOnDelete().value() ) - ? ForeignKey.ReferentialAction.CASCADE - : ForeignKey.ReferentialAction.NO_ACTION; + public boolean isCascadeDeleteEnabled() { + return "cascade".equals( keyElement.getOnDelete().value() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/ForeignKeyContributingSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/ForeignKeyContributingSource.java index 85318e1e3b..3773e83157 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/ForeignKeyContributingSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/ForeignKeyContributingSource.java @@ -42,6 +42,14 @@ public interface ForeignKeyContributingSource { */ public String getExplicitForeignKeyName(); + /** + * Is "cascade delete" enabled for the foreign key? In other words, if a record in the parent (referenced) + * table is deleted, should the corresponding records in the child table automatically be deleted? + * + * @return true, if the cascade delete is enabled; false, otherwise. + */ + public boolean isCascadeDeleteEnabled(); + /** * Retrieve the delegate for resolving foreign key target columns. This corresponds directly to * HBM {@code } and JPA {@link javax.persistence.JoinColumn} mappings. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeKeySource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeKeySource.java index 467262067f..8956c4dea1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeKeySource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeKeySource.java @@ -31,5 +31,5 @@ import org.hibernate.metamodel.spi.relational.ForeignKey; * @author Steve Ebersole */ public interface PluralAttributeKeySource extends ForeignKeyContributingSource, RelationalValueSourceContainer { - public ForeignKey.ReferentialAction getOnDeleteAction(); + public boolean isCascadeDeleteEnabled(); } diff --git a/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd b/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd index 21989e7032..fe10031fef 100644 --- a/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd @@ -1233,6 +1233,7 @@ + diff --git a/hibernate-core/src/test/java/org/hibernate/serialization/SessionFactorySerializationTest.java b/hibernate-core/src/test/java/org/hibernate/serialization/SessionFactorySerializationTest.java index 8d4dfca4b6..86522ac63f 100644 --- a/hibernate-core/src/test/java/org/hibernate/serialization/SessionFactorySerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/serialization/SessionFactorySerializationTest.java @@ -36,6 +36,7 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.internal.SessionFactoryRegistry; import org.hibernate.internal.util.SerializationHelper; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.type.SerializationException; import org.junit.Test; @@ -47,6 +48,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase { public static final String NAME = "mySF"; @Test + @FailureExpectedWithNewMetamodel public void testNamedSessionFactorySerialization() throws Exception { Configuration cfg = new Configuration() .setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME ) @@ -73,6 +75,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testUnNamedSessionFactorySerialization() throws Exception { // IMPL NOTE : this test is a control to testNamedSessionFactorySerialization // here, the test should fail based just on attempted uuid resolution diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java index 2bd1616917..9fe5e7e0bd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java @@ -58,7 +58,6 @@ import org.junit.Test; * * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class BulkManipulationTest extends BaseCoreFunctionalTestCase { public String[] getMappings() { return new String[] { @@ -1349,7 +1348,6 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-8476" ) - @FailureExpectedWithNewMetamodel public void testManyToManyBulkDelete() { Session s = openSession(); Transaction t = s.beginTransaction(); @@ -1387,6 +1385,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-1917" ) + @FailureExpectedWithNewMetamodel public void testManyToManyBulkDeleteMultiTable() { Session s = openSession(); Transaction t = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java b/hibernate-core/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java index f003468dd3..31baf5ba7c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java @@ -38,7 +38,6 @@ import static org.junit.Assert.assertEquals; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class IdentifierPropertyReferencesTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/immutable/ImmutableTest.java b/hibernate-core/src/test/java/org/hibernate/test/immutable/ImmutableTest.java index 88a4403156..eeedae4c36 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/immutable/ImmutableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/immutable/ImmutableTest.java @@ -52,7 +52,6 @@ import static org.junit.Assert.fail; /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel public class ImmutableTest extends BaseCoreFunctionalTestCase { private static class TextAsMaterializedClobType extends AbstractSingleColumnStandardBasicType { public final static TextAsMaterializedClobType INSTANCE = new TextAsMaterializedClobType(); @@ -79,6 +78,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testChangeImmutableEntityProxyToModifiable() { Contract c = new Contract( null, "gavin", "phone"); ContractVariation cv1 = new ContractVariation(1, c); @@ -140,6 +140,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testChangeImmutableEntityToModifiable() { Contract c = new Contract( null, "gavin", "phone"); ContractVariation cv1 = new ContractVariation(1, c); @@ -931,7 +932,12 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { t = s.beginTransaction(); c = ( Contract ) s.merge( c ); assertTrue( s.isReadOnly( c ) ); - assertTrue( Hibernate.isInitialized( c.getVariations() ) ); + // Contract has 2 collections (subcontracts and variations); + // only 1 will be eagerly loaded with the merge; + // the 1 that is eagerly loaded will be the one that gets bound + // first; since this is indeterminate, we cannot test if the + // collection is initialized. + assertEquals( 2, c.getVariations().size() ); Iterator it = c.getVariations().iterator(); cv1 = (ContractVariation) it.next(); cv2 = (ContractVariation) it.next(); @@ -986,7 +992,12 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { c.setCustomerName("foo bar"); c = ( Contract ) s.merge( c ); assertTrue( s.isReadOnly( c ) ); - assertTrue( Hibernate.isInitialized( c.getVariations() ) ); + // Contract has 2 collections (subcontracts and variations); + // only 1 will be eagerly loaded with the merge; + // the 1 that is eagerly loaded will be the one that gets bound + // first; since this is indeterminate, we cannot test if the + // collection is initialized. + assertEquals( 2, c.getVariations().size() ); Iterator it = c.getVariations().iterator(); cv1 = (ContractVariation) it.next(); cv2 = (ContractVariation) it.next(); @@ -1042,7 +1053,12 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { cv1.setText("blah blah"); c = ( Contract ) s.merge( c ); assertTrue( s.isReadOnly( c ) ); - assertTrue( Hibernate.isInitialized( c.getVariations() ) ); + // Contract has 2 collections (subcontracts and variations); + // only 1 will be eagerly loaded with the merge; + // the 1 that is eagerly loaded will be the one that gets bound + // first; since this is indeterminate, we cannot test if the + // collection is initialized. + assertEquals( 2, c.getVariations().size() ); Iterator it = c.getVariations().iterator(); cv1 = (ContractVariation) it.next(); cv2 = (ContractVariation) it.next(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java index 09ff2a438e..67b39bac6f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/EagerKeyManyToOneTest.java @@ -39,7 +39,6 @@ import org.hibernate.integrator.spi.Integrator; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.service.spi.SessionFactoryServiceRegistry; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -50,7 +49,6 @@ import static org.junit.Assert.fail; * @author Steve Ebersole */ @SuppressWarnings( {"unchecked"}) -@FailureExpectedWithNewMetamodel public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/LazyKeyManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/LazyKeyManyToOneTest.java index c0bbdd78e2..3d73a4e692 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/LazyKeyManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/component/LazyKeyManyToOneTest.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -37,7 +36,6 @@ import static org.junit.Assert.assertEquals; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class LazyKeyManyToOneTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/embedded/KeyManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/embedded/KeyManyToOneTest.java index 04e20506a3..350f93713c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/embedded/KeyManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/embedded/KeyManyToOneTest.java @@ -32,7 +32,6 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.criterion.Restrictions; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -40,7 +39,6 @@ import static org.junit.Assert.assertEquals; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class KeyManyToOneTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/ondelete/KeyManyToOneCascadeDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/ondelete/KeyManyToOneCascadeDeleteTest.java index e5f26471d1..a76ea49571 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/ondelete/KeyManyToOneCascadeDeleteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/bidir/ondelete/KeyManyToOneCascadeDeleteTest.java @@ -29,7 +29,6 @@ import org.junit.Assert; import org.junit.Test; import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -38,7 +37,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @RequiresDialectFeature(DialectChecks.SupportsCascadeDeleteCheck.class) -@FailureExpectedWithNewMetamodel public class KeyManyToOneCascadeDeleteTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/unidir/ondelete/KeyManyToOneCascadeDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/unidir/ondelete/KeyManyToOneCascadeDeleteTest.java index 94cd3e16ce..f69dc98e9e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/unidir/ondelete/KeyManyToOneCascadeDeleteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/keymanytoone/unidir/ondelete/KeyManyToOneCascadeDeleteTest.java @@ -29,7 +29,6 @@ import org.junit.Assert; import org.junit.Test; import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -38,7 +37,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @RequiresDialectFeature(DialectChecks.SupportsCascadeDeleteCheck.class) -@FailureExpectedWithNewMetamodel public class KeyManyToOneCascadeDeleteTest extends BaseCoreFunctionalTestCase { @Override public String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/loadplans/plans/LoadPlanStructureAssertionTest.java b/hibernate-core/src/test/java/org/hibernate/test/loadplans/plans/LoadPlanStructureAssertionTest.java index 1cf1b4b974..5a5cced70b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/loadplans/plans/LoadPlanStructureAssertionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/loadplans/plans/LoadPlanStructureAssertionTest.java @@ -80,12 +80,9 @@ public class LoadPlanStructureAssertionTest extends BaseUnitTestCase { } @Test - @FailureExpectedWithNewMetamodel public void testSpecialOneToOne() { // tests the mappings defined in org.hibernate.test.onetoone.joined.JoinedSubclassOneToOneTest - // metamodel : XSD problem : key-many-to-one needs to add on-delete attribute - Configuration cfg = new Configuration(); cfg.addResource( "org/hibernate/test/onetoone/formula/Person.hbm.xml" ); SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java b/hibernate-core/src/test/java/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java index 82c6f4d1dd..388233493b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java @@ -41,7 +41,6 @@ import org.hibernate.loader.plan.exec.query.spi.NamedParameterContext; import org.hibernate.loader.plan.exec.spi.LoadQueryDetails; import org.hibernate.loader.plan.spi.LoadPlan; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.type.Type; import org.junit.Test; @@ -56,7 +55,6 @@ import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class NonEncapsulatedCompositeIdResultSetProcessorTest extends BaseCoreFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java b/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java index 3ad33df6a5..d47e424c45 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java @@ -28,14 +28,12 @@ import org.hibernate.persister.walking.spi.MetamodelGraphWalker; import org.junit.Test; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.test.onetoone.formula.Address; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class KeyManyToOneWalkingTest extends BaseCoreFunctionalTestCase { @Override protected String[] getMappings() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/formula/OneToOneFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/formula/OneToOneFormulaTest.java index 3e544e80e2..c7925a0cee 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/formula/OneToOneFormulaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/formula/OneToOneFormulaTest.java @@ -49,7 +49,6 @@ import static org.junit.Assert.assertTrue; /** * @author Gavin King */ -@FailureExpectedWithNewMetamodel public class OneToOneFormulaTest extends BaseCoreFunctionalTestCase { private static class TextAsMaterializedClobType extends AbstractSingleColumnStandardBasicType { public final static TextAsMaterializedClobType INSTANCE = new TextAsMaterializedClobType(); @@ -151,6 +150,7 @@ public class OneToOneFormulaTest extends BaseCoreFunctionalTestCase { } @Test + @FailureExpectedWithNewMetamodel public void testOneToOneEmbeddedCompositeKey() { Person p = new Person(); p.setName("Gavin King"); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 441f0845eb..75a13467de 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -174,11 +174,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { } protected void rebuildSessionFactory() { - if ( sessionFactory == null ) { - return; - } try { - sessionFactory.close(); + releaseSessionFactory(); } catch (Exception ignore) { }