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 e9fff81bb7..d077a358a2 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 @@ -1385,6 +1385,7 @@ public class Binder { return metadata.getTypeResolver().getTypeFactory().manyToOne( referencedEntityBinding.getEntity().getName(), + uniqueKeyAttributeName == null, uniqueKeyAttributeName, attributeSource.getFetchTiming() != FetchTiming.IMMEDIATE, attributeSource.isUnWrapProxy(), @@ -1492,6 +1493,7 @@ public class Binder { return metadata.getTypeResolver().getTypeFactory().oneToOne( referencedEntityBinding.getEntity().getName(), attributeSource.getForeignKeyDirection(), + uniqueKeyAttributeName == null, uniqueKeyAttributeName, attributeSource.getFetchTiming() != FetchTiming.IMMEDIATE, attributeSource.isUnWrapProxy(), @@ -1504,6 +1506,7 @@ public class Binder { return metadata.getTypeResolver().getTypeFactory().specialOneToOne( referencedEntityBinding.getEntity().getName(), attributeSource.getForeignKeyDirection(), + uniqueKeyAttributeName == null, uniqueKeyAttributeName, attributeSource.getFetchTiming() != FetchTiming.IMMEDIATE, attributeSource.isUnWrapProxy(), @@ -2048,6 +2051,7 @@ public class Binder { Type resolvedElementType = metadata.getTypeResolver().getTypeFactory().manyToOne( referencedEntityBinding.getEntity().getName(), + true, null, false, false, diff --git a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java index 0c91ee2584..460728468f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java @@ -107,12 +107,25 @@ public abstract class EntityType extends AbstractType implements AssociationType String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy) { + this(scope, entityName, referenceToPrimaryKey, uniqueKeyPropertyName, eager, unwrapProxy, null); + } + + + protected EntityType( + TypeFactory.TypeScope scope, + String entityName, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean eager, + boolean unwrapProxy, + Class returnedClass) { this.scope = scope; this.associatedEntityName = entityName; this.uniqueKeyPropertyName = uniqueKeyPropertyName; this.eager = eager; this.unwrapProxy = unwrapProxy; this.referenceToPrimaryKey = referenceToPrimaryKey; + this.returnedClass = returnedClass; } 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 9e16f42d93..9c1e558bd7 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -95,10 +95,25 @@ public class ManyToOneType extends EntityType { boolean unwrapProxy, boolean ignoreNotFound, boolean isLogicalOneToOne) { - super( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, !lazy, unwrapProxy ); + this( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, isLogicalOneToOne, null); + } + + + public ManyToOneType( + TypeFactory.TypeScope scope, + String referencedEntityName, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean lazy, + boolean unwrapProxy, + boolean ignoreNotFound, + boolean isLogicalOneToOne, + Class returnedClass) { + super( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, !lazy, unwrapProxy, returnedClass ); this.ignoreNotFound = ignoreNotFound; this.isLogicalOneToOne = isLogicalOneToOne; } + protected boolean isNullable() { return ignoreNotFound; } 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 9783148b13..d20f951a09 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java @@ -81,6 +81,23 @@ public class OneToOneType extends EntityType { this.entityName = entityName; } + public OneToOneType( + TypeFactory.TypeScope scope, + String referencedEntityName, + ForeignKeyDirection foreignKeyType, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean lazy, + boolean unwrapProxy, + String entityName, + String propertyName, + Class returnedClass) { + super( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, !lazy, unwrapProxy, returnedClass ); + this.foreignKeyType = foreignKeyType; + this.propertyName = propertyName; + this.entityName = entityName; + } + public String getPropertyName() { return propertyName; diff --git a/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java index 8fd9d6e8ce..cb395bd884 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java @@ -86,6 +86,7 @@ public class SpecialOneToOneType extends OneToOneType { TypeFactory.TypeScope scope, String referencedEntityName, ForeignKeyDirection foreignKeyType, + boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, @@ -96,6 +97,7 @@ public class SpecialOneToOneType extends OneToOneType { scope, referencedEntityName, foreignKeyType, + referenceToPrimaryKey, uniqueKeyPropertyName, lazy, unwrapProxy, @@ -104,7 +106,8 @@ public class SpecialOneToOneType extends OneToOneType { returnedClass ); } - + + public int getColumnSpan(Mapping mapping) throws MappingException { return super.getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java b/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java index 2f81dcd8ba..29ff5b72b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java @@ -237,6 +237,20 @@ public final class TypeFactory implements Serializable { return new OneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey, uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName ); } + + public EntityType oneToOne( + String persistentClass, + ForeignKeyDirection foreignKeyType, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean lazy, + boolean unwrapProxy, + String entityName, + String propertyName, + Class returnedClass) { + return new OneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey, + uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName, returnedClass ); + } /** * @deprecated Use {@link #specialOneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead. @@ -267,6 +281,20 @@ public final class TypeFactory implements Serializable { uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName ); } + public EntityType specialOneToOne( + String persistentClass, + ForeignKeyDirection foreignKeyType, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean lazy, + boolean unwrapProxy, + String entityName, + String propertyName, + Class returnedClass) { + return new SpecialOneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey, + uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName, returnedClass ); + } + // many-to-one type builders ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -294,7 +322,6 @@ public final class TypeFactory implements Serializable { isLogicalOneToOne ); } - public EntityType manyToOne( String persistentClass, boolean referenceToPrimaryKey, @@ -303,6 +330,18 @@ public final class TypeFactory implements Serializable { boolean unwrapProxy, boolean ignoreNotFound, boolean isLogicalOneToOne) { + return manyToOne( persistentClass, referenceToPrimaryKey, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, isLogicalOneToOne, null ); + } + + public EntityType manyToOne( + String persistentClass, + boolean referenceToPrimaryKey, + String uniqueKeyPropertyName, + boolean lazy, + boolean unwrapProxy, + boolean ignoreNotFound, + boolean isLogicalOneToOne, + Class returnedClass) { return new ManyToOneType( typeScope, persistentClass, @@ -311,7 +350,8 @@ public final class TypeFactory implements Serializable { lazy, unwrapProxy, ignoreNotFound, - isLogicalOneToOne + isLogicalOneToOne, + returnedClass ); } diff --git a/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeAttributeResultSetProcessorTest.java b/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeAttributeResultSetProcessorTest.java index ca0cd1aeab..a0875de455 100644 --- a/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeAttributeResultSetProcessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeAttributeResultSetProcessorTest.java @@ -63,6 +63,7 @@ import org.hibernate.loader.spi.NoOpLoadPlanAdvisor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.test.component.cascading.toone.PersonalInfo; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.ExtraAssertions; @@ -131,6 +132,7 @@ public class EncapsulatedCompositeAttributeResultSetProcessorTest extends BaseCo } @Test + @FailureExpectedWithNewMetamodel public void testNestedCompositeElementCollectionProcessing() throws Exception { // create some test data Session session = openSession(); diff --git a/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeIdResultSetProcessorTest.java b/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeIdResultSetProcessorTest.java index 2482fcf4ca..8b0968f70c 100644 --- a/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeIdResultSetProcessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/loader/EncapsulatedCompositeIdResultSetProcessorTest.java @@ -55,6 +55,7 @@ import org.hibernate.loader.spi.LoadQueryAliasResolutionContext; import org.hibernate.loader.spi.NamedParameterContext; import org.hibernate.loader.spi.NoOpLoadPlanAdvisor; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.ExtraAssertions; import org.hibernate.type.Type; @@ -128,6 +129,7 @@ public class EncapsulatedCompositeIdResultSetProcessorTest extends BaseCoreFunct } @Test + @FailureExpectedWithNewMetamodel public void testCompositeIdWithKeyManyToOne() throws Exception { final String cardId = "ace-of-spades"; diff --git a/hibernate-core/src/test/java/org/hibernate/loader/EntityWithNonLazyOneToManyListResultSetProcessorTest.java b/hibernate-core/src/test/java/org/hibernate/loader/EntityWithNonLazyOneToManyListResultSetProcessorTest.java index abd4dadf7f..ae488eb74b 100644 --- a/hibernate-core/src/test/java/org/hibernate/loader/EntityWithNonLazyOneToManyListResultSetProcessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/loader/EntityWithNonLazyOneToManyListResultSetProcessorTest.java @@ -56,6 +56,7 @@ import org.hibernate.loader.spi.LoadQueryAliasResolutionContext; import org.hibernate.loader.spi.NamedParameterContext; import org.hibernate.loader.spi.NoOpLoadPlanAdvisor; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.ExtraAssertions; @@ -75,6 +76,7 @@ public class EntityWithNonLazyOneToManyListResultSetProcessorTest extends BaseCo } @Test + @FailureExpectedWithNewMetamodel public void testEntityWithList() throws Exception { final EntityPersister entityPersister = sessionFactory().getEntityPersister( Poster.class.getName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java b/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java index de0e913dc8..6872d25415 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java @@ -380,7 +380,7 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase { s.getTransaction().commit(); s.close(); } - + @Override protected void prepareTest() { Session s = openSession(); s.getTransaction().begin(); @@ -409,7 +409,7 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase { s.getTransaction().commit(); s.close(); } - + @Override protected void cleanupTest() { Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/named/basic/BasicNamedEntityGraphTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/named/basic/BasicNamedEntityGraphTest.java index b6109b4a3a..c7ec53fdea 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/named/basic/BasicNamedEntityGraphTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/named/basic/BasicNamedEntityGraphTest.java @@ -26,6 +26,7 @@ package org.hibernate.jpa.test.graphs.named.basic; import javax.persistence.EntityGraph; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.junit.Test; @@ -41,6 +42,7 @@ public class BasicNamedEntityGraphTest extends BaseEntityManagerFunctionalTestCa } @Test + @FailureExpectedWithNewMetamodel public void testIt() { EntityGraph graph = getOrCreateEntityManager().getEntityGraph( "Person" ); assertNotNull( graph ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java index 8e0b857ec8..1575b0cc47 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java @@ -81,7 +81,6 @@ import static org.junit.Assert.fail; @SuppressWarnings("unchecked") public class PackagedEntityManagerTest extends PackagingTestCase { @Test - @FailureExpectedWithNewMetamodel public void testDefaultPar() throws Exception { File testPackage = buildDefaultPar(); addPackageToClasspath( testPackage ); @@ -117,7 +116,6 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test - @FailureExpectedWithNewMetamodel public void testDefaultParForPersistence_1_0() throws Exception { File testPackage = buildDefaultPar_1_0(); addPackageToClasspath( testPackage ); @@ -193,7 +191,6 @@ public class PackagedEntityManagerTest extends PackagingTestCase { } @Test - @FailureExpectedWithNewMetamodel public void testExplodedPar() throws Exception { File testPackage = buildExplodedPar(); addPackageToClasspath( testPackage );