diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java index 1de727ef01..18de673b1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java @@ -1695,8 +1695,9 @@ public final class HbmBinder { oneToOne.setConstrained( constrained ); oneToOne.setForeignKeyType( constrained ? - ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : - ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ); + ForeignKeyDirection.FROM_PARENT : + ForeignKeyDirection.TO_PARENT + ); initOuterJoinFetchSetting( node, oneToOne ); initLaziness( node, oneToOne, mappings, true ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java index a428cd3465..8f8b863bfe 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java @@ -104,8 +104,8 @@ public class OneToOneSecondPass implements SecondPass { if ( !optional ) value.setConstrained( true ); value.setForeignKeyType( value.isConstrained() ? - ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : - ForeignKeyDirection.FOREIGN_KEY_TO_PARENT + ForeignKeyDirection.FROM_PARENT : + ForeignKeyDirection.TO_PARENT ); PropertyBinder binder = new PropertyBinder(); binder.setName( propertyName ); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java index 5d00d6afad..652df90bfb 100755 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java @@ -212,14 +212,14 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme // copy created before we actually copy //cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE); super.cascadeBeforeSave(source, persister, entity, copyCache); - copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT); + copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT ); saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache ); // cascade first, so that all unsaved objects get their // copy created before we actually copy super.cascadeAfterSave(source, persister, entity, copyCache); - copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT); + copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT ); event.setResult( copy ); } @@ -392,7 +392,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme final Object[] copiedValues; - if ( foreignKeyDirection == ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ) { + if ( foreignKeyDirection == ForeignKeyDirection.TO_PARENT ) { // this is the second pass through on a merge op, so here we limit the // replacement to associations types (value types were already replaced // during the first pass) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java b/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java index cda4f84bc2..3aaa7240fc 100755 --- a/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java @@ -760,7 +760,7 @@ public class JoinWalker { protected boolean isDuplicateAssociation(final String lhsTable, final String[] lhsColumnNames, final AssociationType type) { final String foreignKeyTable; final String[] foreignKeyColumns; - if ( type.getForeignKeyDirection()==ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT ) { + if ( type.getForeignKeyDirection()==ForeignKeyDirection.FROM_PARENT ) { foreignKeyTable = lhsTable; foreignKeyColumns = lhsColumnNames; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java index 0f44938e1b..e55a913030 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java @@ -383,7 +383,7 @@ public abstract class AbstractStandardBasicType Object owner, Map copyCache, ForeignKeyDirection foreignKeyDirection) { - return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT == foreignKeyDirection + return ForeignKeyDirection.FROM_PARENT == foreignKeyDirection ? getReplacement( (T) original, (T) target, session ) : target; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractType.java index 38fddf26e9..d1c9a2dfb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractType.java @@ -173,7 +173,7 @@ public abstract class AbstractType implements Type { include = atype.getForeignKeyDirection()==foreignKeyDirection; } else { - include = ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT==foreignKeyDirection; + include = ForeignKeyDirection.FROM_PARENT ==foreignKeyDirection; } return include ? replace(original, target, session, owner, copyCache) : target; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/AnyType.java b/hibernate-core/src/main/java/org/hibernate/type/AnyType.java index 9f5a0da65f..de03720c09 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AnyType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AnyType.java @@ -327,8 +327,8 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT } public ForeignKeyDirection getForeignKeyDirection() { - //return AssociationType.FOREIGN_KEY_TO_PARENT; //this is better but causes a transient object exception... - return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT; + //return AssociationType.TO_PARENT; //this is better but causes a transient object exception... + return ForeignKeyDirection.FROM_PARENT; } public boolean isAssociationType() { diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index 84ab515ff9..7b3d74ad49 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -321,7 +321,7 @@ public abstract class CollectionType extends AbstractType implements Association } public ForeignKeyDirection getForeignKeyDirection() { - return ForeignKeyDirection.FOREIGN_KEY_TO_PARENT; + return ForeignKeyDirection.TO_PARENT; } /** diff --git a/hibernate-core/src/main/java/org/hibernate/type/ForeignKeyDirection.java b/hibernate-core/src/main/java/org/hibernate/type/ForeignKeyDirection.java index 284ef5971e..3eb8712030 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ForeignKeyDirection.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ForeignKeyDirection.java @@ -23,52 +23,39 @@ */ package org.hibernate.type; -import java.io.Serializable; - import org.hibernate.engine.internal.Cascade; /** * Represents directionality of the foreign key constraint + * * @author Gavin King */ -public abstract class ForeignKeyDirection implements Serializable { - protected ForeignKeyDirection() {} +public enum ForeignKeyDirection { + /** + * A foreign key from child to parent + */ + TO_PARENT { + @Override + public boolean cascadeNow(int cascadePoint) { + return cascadePoint != Cascade.BEFORE_INSERT_AFTER_DELETE; + } + + }, + /** + * A foreign key from parent to child + */ + FROM_PARENT { + @Override + public boolean cascadeNow(int cascadePoint) { + return cascadePoint != Cascade.AFTER_INSERT_BEFORE_DELETE; + } + }; + /** * Should we cascade at this cascade point? + * * @see org.hibernate.engine.internal.Cascade */ public abstract boolean cascadeNow(int cascadePoint); - /** - * A foreign key from child to parent - */ - public static final ForeignKeyDirection FOREIGN_KEY_TO_PARENT = new ForeignKeyDirection() { - public boolean cascadeNow(int cascadePoint) { - return cascadePoint!=Cascade.BEFORE_INSERT_AFTER_DELETE; - } - - public String toString() { - return "toParent"; - } - - Object readResolve() { - return FOREIGN_KEY_TO_PARENT; - } - }; - /** - * A foreign key from parent to child - */ - public static final ForeignKeyDirection FOREIGN_KEY_FROM_PARENT = new ForeignKeyDirection() { - public boolean cascadeNow(int cascadePoint) { - return cascadePoint!= Cascade.AFTER_INSERT_BEFORE_DELETE; - } - - public String toString() { - return "fromParent"; - } - - Object readResolve() { - return FOREIGN_KEY_FROM_PARENT; - } - }; } \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java index 1f0d42268c..09a7448098 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -143,7 +143,7 @@ public class ManyToOneType extends EntityType { } public ForeignKeyDirection getForeignKeyDirection() { - return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT; + return ForeignKeyDirection.FROM_PARENT; } public Object hydrate( diff --git a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java index 60a33ed957..fa1a17c7e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java @@ -142,7 +142,7 @@ public class OneToOneType extends EntityType { } protected boolean isNullable() { - return foreignKeyType==ForeignKeyDirection.FOREIGN_KEY_TO_PARENT; + return foreignKeyType==ForeignKeyDirection.TO_PARENT; } public boolean useLHSPrimaryKey() {