From 834fa2140f7f7e99aee783843c7a8819cdf5a4bb Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 3 Jun 2011 10:49:15 -0700 Subject: [PATCH] HHH-6290 : Add EntityBinding.isRoot() --- .../org/hibernate/metamodel/binding/EntityBinding.java | 10 ++++++++++ .../source/annotations/entity/EntityBinder.java | 2 +- .../metamodel/source/hbm/RootEntityBinder.java | 2 +- .../metamodel/binding/AbstractBasicBindingTests.java | 1 + .../metamodel/binding/SimpleValueBindingTests.java | 2 +- .../source/annotations/entity/InheritanceTypeTest.java | 4 ++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java index 80d2127c08..192b2ffffd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java @@ -56,6 +56,8 @@ import org.hibernate.metamodel.source.hbm.util.MappingHelper; */ public class EntityBinding { private final EntityIdentifier entityIdentifier = new EntityIdentifier( this ); + private final boolean isRoot; + private InheritanceType entityInheritanceType; private EntityDiscriminator entityDiscriminator; private SimpleAttributeBinding versionBinding; @@ -94,6 +96,10 @@ public class EntityBinding { private List synchronizedTableNames; + public EntityBinding(boolean isRoot) { + this.isRoot = isRoot; + } + // TODO: change to intialize from Doimain public void fromHbmXml(MappingDefaults defaults, XMLClass entityClazz, Entity entity) { this.entity = entity; @@ -175,6 +181,10 @@ public class EntityBinding { isAbstract = entityClazz.isAbstract(); } + public boolean isRoot() { + return isRoot; + } + public Entity getEntity() { return entity; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java index 654a707fa4..2bbc4833f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java @@ -85,7 +85,7 @@ public class EntityBinder { } public void bind() { - EntityBinding entityBinding = new EntityBinding(); + EntityBinding entityBinding = new EntityBinding( configuredClass.isRoot() ); bindJpaEntityAnnotation( entityBinding ); bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java index 96206158ac..1b9347def1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java @@ -60,7 +60,7 @@ class RootEntityBinder extends AbstractEntityBinder { throw new MappingException( "Unable to determine entity name" ); } - EntityBinding entityBinding = new EntityBinding(); + EntityBinding entityBinding = new EntityBinding( true ); basicEntityBinding( xmlClazz, entityBinding, null ); basicTableBinding( xmlClazz, entityBinding ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/AbstractBasicBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/AbstractBasicBindingTests.java index 37a1a6c9e6..3754334ed6 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/AbstractBasicBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/AbstractBasicBindingTests.java @@ -123,6 +123,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertNotNull( entityBinding ); assertNotNull( entityBinding.getEntityIdentifier() ); assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() ); + assertTrue( entityBinding.isRoot() ); AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" ); assertNotNull( idAttributeBinding ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java index ffe2103119..2160653407 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java @@ -52,7 +52,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { public void testBasicMiddleOutBuilding() { Table table = new Table( new Schema( null, null ), "the_table" ); Entity entity = new Entity( "TheEntity", null ); - EntityBinding entityBinding = new EntityBinding(); + EntityBinding entityBinding = new EntityBinding( true ); entityBinding.setEntity( entity ); entityBinding.setBaseTable( table ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/InheritanceTypeTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/InheritanceTypeTest.java index 331f3a0cae..cf914916aa 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/InheritanceTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/InheritanceTypeTest.java @@ -32,7 +32,9 @@ import org.junit.Test; import org.hibernate.metamodel.binding.EntityBinding; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.assertTrue; /** * @author Hardy Ferentschik @@ -42,6 +44,7 @@ public class InheritanceTypeTest extends BaseAnnotationBindingTestCase { public void testNoInheritance() { buildMetadataSources( SingleEntity.class ); EntityBinding entityBinding = getEntityBinding( SingleEntity.class ); + assertTrue( entityBinding.isRoot() ); assertNull( entityBinding.getEntityDiscriminator() ); } @@ -51,6 +54,7 @@ public class InheritanceTypeTest extends BaseAnnotationBindingTestCase { RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class ); EntityBinding entityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class ); + assertFalse( entityBinding.isRoot() ); assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() ); }