From 49cf328bb87cfaa77df2734c588e1196681abbc3 Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Thu, 19 May 2011 17:01:10 +0200 Subject: [PATCH] HHH-6172 Cleaning up AbstractBasicBindingTests --- .../binding/AbstractAttributeBinding.java | 5 -- .../metamodel/binding/AttributeBinding.java | 15 +--- .../binding/ManyToOneAttributeBinding.java | 37 ++++----- .../annotations/entity/EntityBinder.java | 5 +- .../source/internal/MetadataImpl.java | 3 + .../binding/AbstractBasicBindingTests.java | 75 ++++++------------- .../binding/BasicAnnotationBindingTests.java | 24 ++---- .../binding/BasicHbmBindingTests.java | 37 +++------ .../binding/EntityWithManyToOne.hbm.xml | 15 ---- .../metamodel/binding/ManyToOneEntity.hbm.xml | 15 ++++ ...ithManyToOne.java => ManyToOneEntity.java} | 26 ++++--- .../binding/MiscAnnotationBindingTest.java | 2 +- .../annotations/entity/CacheBindingTests.java | 8 +- .../entity/InheritanceTypeTest.java | 4 +- 14 files changed, 104 insertions(+), 167 deletions(-) delete mode 100644 hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml create mode 100644 hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml rename hibernate-core/src/test/java/org/hibernate/metamodel/binding/{EntityWithManyToOne.java => ManyToOneEntity.java} (78%) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractAttributeBinding.java index 5cfdb2f9eb..5e746a0358 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractAttributeBinding.java @@ -172,11 +172,6 @@ public abstract class AbstractAttributeBinding implements AttributeBinding { : Collections.singletonList( (SimpleValue) value ); } - @Override - public TableSpecification getTable() { - return getValue().getTable(); - } - @Override public String getPropertyAccessorName() { return propertyAccessorName; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBinding.java index c68b18b298..ef616db93e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBinding.java @@ -74,27 +74,14 @@ public interface AttributeBinding { public Map getMetaAttributes(); /** - * In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method + * @return In the case that {@link #getValue()} represents a {@link org.hibernate.metamodel.relational.Tuple} this method * gives access to its compound values. In the case of {@link org.hibernate.metamodel.relational.SimpleValue}, * we return an Iterable over that single simple value. - * - * @return */ public Iterable getValues(); - /** - * @return - * - * @deprecated Use {@link #getValue()}.{@link Value#getTable() getTable()} instead; to be removed on completion of new metamodel code - */ - @Deprecated - public TableSpecification getTable(); - public String getPropertyAccessorName(); - /** - * @return - */ public boolean hasFormula(); public boolean isAlternateUniqueKey(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ManyToOneAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ManyToOneAttributeBinding.java index e076140062..a00197ae1e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ManyToOneAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ManyToOneAttributeBinding.java @@ -26,11 +26,10 @@ package org.hibernate.metamodel.binding; import java.util.Iterator; import org.hibernate.MappingException; -import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState; +import org.hibernate.metamodel.relational.Column; import org.hibernate.metamodel.relational.ForeignKey; import org.hibernate.metamodel.relational.SimpleValue; -import org.hibernate.metamodel.relational.Column; -import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState; import org.hibernate.metamodel.relational.state.ManyToOneRelationalState; /** @@ -56,13 +55,6 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements isPropertyReference = state.getReferencedAttributeName() != null; referencedAttributeName = state.getReferencedAttributeName(); referencedEntityName = state.getReferencedEntityName(); - if ( referencedEntityName == null ) { - referencedEntityName = - ReflectHelper.reflectedPropertyClass( - getEntityBinding().getEntity().getName(), - state.getAttributeName() - ).getName(); - } return this; } @@ -84,7 +76,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements public final String getReferencedAttributeName() { if ( referencedAttributeName == null ) { throw new IllegalStateException( - "Referenced attribute name is not available." + "Referenced attribute name is not available." ); } return referencedAttributeName; @@ -95,7 +87,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements } public final EntityBinding getReferencedEntityBinding() { - if ( ! isReferenceResolved() ) { + if ( !isReferenceResolved() ) { throw new IllegalStateException( "EntityBinding reference has not be referenced." ); } // TODO: throw exception if referencedEntityBinding is null? @@ -103,7 +95,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements } public final void resolveReference(AttributeBinding referencedAttributeBinding) { - if ( ! referencedEntityName.equals( referencedAttributeBinding.getEntityBinding().getEntity().getName() ) ) { + if ( !referencedEntityName.equals( referencedAttributeBinding.getEntityBinding().getEntity().getName() ) ) { throw new IllegalStateException( "attempt to set EntityBinding with name: [" + referencedAttributeBinding.getEntityBinding().getEntity().getName() + @@ -113,10 +105,10 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements if ( referencedAttributeName == null ) { referencedAttributeName = referencedAttributeBinding.getAttribute().getName(); } - else if ( ! referencedAttributeName.equals( referencedAttributeBinding.getAttribute().getName() ) ) { + else if ( !referencedAttributeName.equals( referencedAttributeBinding.getAttribute().getName() ) ) { throw new IllegalStateException( "Inconsistent attribute name; expected: " + referencedAttributeName + - "actual: " + referencedAttributeBinding.getAttribute().getName() + "actual: " + referencedAttributeBinding.getAttribute().getName() ); } this.referencedAttributeBinding = referencedAttributeBinding; @@ -125,18 +117,21 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements private void buildForeignKey() { // TODO: move this stuff to relational model - ForeignKey foreignKey = getTable().createForeignKey( referencedAttributeBinding.getTable(), foreignKeyName ); + ForeignKey foreignKey = getValue().getTable() + .createForeignKey( referencedAttributeBinding.getValue().getTable(), foreignKeyName ); Iterator referencingValueIterator = getValues().iterator(); - Iterator targetValueIterator = referencedAttributeBinding.getValues().iterator(); + Iterator targetValueIterator = referencedAttributeBinding.getValues().iterator(); while ( referencingValueIterator.hasNext() ) { - if ( ! targetValueIterator.hasNext() ) { + if ( !targetValueIterator.hasNext() ) { // TODO: improve this message - throw new MappingException( "number of values in many-to-one reference is greater than number of values in target" ); + throw new MappingException( + "number of values in many-to-one reference is greater than number of values in target" + ); } SimpleValue referencingValue = referencingValueIterator.next(); SimpleValue targetValue = targetValueIterator.next(); if ( Column.class.isInstance( referencingValue ) ) { - if ( ! Column.class.isInstance( targetValue ) ) { + if ( !Column.class.isInstance( targetValue ) ) { // TODO improve this message throw new MappingException( "referencing value is a column, but target is not a column" ); } @@ -159,7 +154,7 @@ public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements public void validate() { // can't check this until both the domain and relational states are initialized... if ( getCascade() != null && getCascade().indexOf( "delete-orphan" ) >= 0 ) { - if ( ! isLogicalOneToOne ) { + if ( !isLogicalOneToOne ) { throw new MappingException( "many-to-one attribute [" + getAttribute().getName() + "] does not support orphan delete as it is not unique" ); 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 3a4fab1aed..60d5845de3 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 @@ -37,7 +37,6 @@ import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.PolymorphismType; import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.binding.Caching; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.SimpleAttributeBinding; @@ -291,7 +290,7 @@ public class EntityBinder { ); String name; if ( jpaEntityAnnotation.value( "name" ) == null ) { - name = StringHelper.unqualify( configuredClass.getName() ); + name = configuredClass.getName(); } else { name = jpaEntityAnnotation.value( "name" ).asString(); @@ -428,7 +427,7 @@ public class EntityBinder { return null; } - EntityBinding parentBinding = meta.getEntityBinding( parent.getSimpleName() ); + EntityBinding parentBinding = meta.getEntityBinding( parent.getName() ); if ( parentBinding == null ) { throw new AssertionFailure( "Parent entity " + parent.getName() + " of entity " + configuredClass.getName() + " not yet created!" diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java index a024b44ad3..99c5a12956 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java @@ -74,6 +74,9 @@ public class MetadataImpl implements Metadata, MetadataImplementor, Serializable private final SharedCacheMode sharedCacheMode; private final Database database = new Database(); + /** + * Maps the fully qualified class name of an entity to its entity binding + */ private Map entityBindingMap = new HashMap(); private Map collectionBindingMap = new HashMap(); private Map fetchProfiles = new HashMap(); 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 3b5aeb9619..c1e363132b 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 @@ -29,8 +29,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.relational.Column; -import org.hibernate.metamodel.source.spi.MetadataImplementor; +import org.hibernate.metamodel.source.internal.MetadataImpl; import org.hibernate.service.BasicServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.internal.BasicServiceRegistryImpl; @@ -50,10 +51,12 @@ import static org.junit.Assert.assertTrue; public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { private BasicServiceRegistryImpl serviceRegistry; + private MetadataSources sources; @Before public void setUp() { serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry(); + sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); } @After @@ -67,56 +70,31 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { @Test public void testSimpleEntityMapping() { - checkSimpleEntityMapping( buildSimpleEntityBinding() ); - } + MetadataImpl metadata = addSourcesForSimpleEntityBinding( sources ); + EntityBinding entityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() ); + assertIdAndSimpleProperty( entityBinding ); - protected void checkSimpleEntityMapping(EntityBinding entityBinding) { - assertNotNull( entityBinding ); - assertNotNull( entityBinding.getEntityIdentifier() ); - assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() ); assertNull( entityBinding.getVersioningValueBinding() ); - - AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" ); - assertNotNull( idAttributeBinding ); - assertSame( idAttributeBinding, entityBinding.getEntityIdentifier().getValueBinding() ); - assertNotNull( idAttributeBinding.getAttribute() ); - assertNotNull( idAttributeBinding.getValue() ); - assertTrue( idAttributeBinding.getValue() instanceof Column ); - - AttributeBinding nameBinding = entityBinding.getAttributeBinding( "name" ); - assertNotNull( nameBinding ); - assertNotNull( nameBinding.getAttribute() ); - assertNotNull( nameBinding.getValue() ); } @Test public void testSimpleVersionedEntityMapping() { - EntityBinding entityBinding = buildSimpleVersionedEntityBinding(); - assertNotNull( entityBinding ); - assertNotNull( entityBinding.getEntityIdentifier() ); - assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() ); + MetadataImpl metadata = addSourcesForSimpleVersionedEntityBinding( sources ); + EntityBinding entityBinding = metadata.getEntityBinding( SimpleVersionedEntity.class.getName() ); + assertIdAndSimpleProperty( entityBinding ); + assertNotNull( entityBinding.getVersioningValueBinding() ); assertNotNull( entityBinding.getVersioningValueBinding().getAttribute() ); - - AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" ); - assertNotNull( idAttributeBinding ); - assertSame( idAttributeBinding, entityBinding.getEntityIdentifier().getValueBinding() ); - assertNotNull( idAttributeBinding.getAttribute() ); - assertNotNull( idAttributeBinding.getValue() ); - assertTrue( idAttributeBinding.getValue() instanceof Column ); - - AttributeBinding nameBinding = entityBinding.getAttributeBinding( "name" ); - assertNotNull( nameBinding ); - assertNotNull( nameBinding.getAttribute() ); - assertNotNull( nameBinding.getValue() ); } @Test public void testEntityWithManyToOneMapping() { - MetadataImplementor metadata = buildMetadataWithManyToOne(); - EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( EntityWithManyToOne.class.getName() ); + MetadataImpl metadata = addSourcesForManyToOne( sources ); + EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() ); - checkSimpleEntityMapping( simpleEntityBinding ); + assertIdAndSimpleProperty( simpleEntityBinding ); + + EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( ManyToOneEntity.class.getName() ); assertTrue( 1 == simpleEntityBinding.getAttributeBinding( "id" ).getEntityReferencingAttributeBindings().size() @@ -127,15 +105,17 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertSame( entityWithManyToOneBinding.getAttributeBinding( "simpleEntity" ), it.next() ); assertFalse( it.hasNext() ); } - /* - @Test - public void testEntityWithElementCollection() { - EntityBinding entityBinding = buildEntityWithElementCollectionBinding(); + public abstract MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources); + + public abstract MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources); + + public abstract MetadataImpl addSourcesForManyToOne(MetadataSources sources); + + protected void assertIdAndSimpleProperty(EntityBinding entityBinding) { assertNotNull( entityBinding ); assertNotNull( entityBinding.getEntityIdentifier() ); assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() ); - assertNull( entityBinding.getVersioningValueBinding() ); AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" ); assertNotNull( idAttributeBinding ); @@ -149,13 +129,4 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertNotNull( nameBinding.getAttribute() ); assertNotNull( nameBinding.getValue() ); } - */ - - public abstract EntityBinding buildSimpleVersionedEntityBinding(); - - public abstract EntityBinding buildSimpleEntityBinding(); - - public abstract MetadataImplementor buildMetadataWithManyToOne(); - - //public abstract EntityBinding buildEntityWithElementCollectionBinding(); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicAnnotationBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicAnnotationBindingTests.java index 5a0d913541..fec39ee5b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicAnnotationBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicAnnotationBindingTests.java @@ -27,8 +27,6 @@ import org.junit.Test; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.source.internal.MetadataImpl; -import org.hibernate.metamodel.source.spi.MetadataImplementor; -import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.testing.FailureExpected; /** @@ -43,26 +41,20 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests { super.testEntityWithManyToOneMapping(); } - public EntityBinding buildSimpleEntityBinding() { - MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); + public MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources) { sources.addAnnotatedClass( SimpleEntity.class ); - MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); + return (MetadataImpl) sources.buildMetadata(); - return metadata.getEntityBinding( SimpleEntity.class.getSimpleName() ); } - public EntityBinding buildSimpleVersionedEntityBinding() { - MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); + public MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources) { sources.addAnnotatedClass( SimpleVersionedEntity.class ); - MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); - - return metadata.getEntityBinding( SimpleVersionedEntity.class.getSimpleName() ); + return (MetadataImpl) sources.buildMetadata(); } - public MetadataImplementor buildMetadataWithManyToOne() { - MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); - sources.addAnnotatedClass( EntityWithManyToOne.class ); - sources.addAnnotatedClass( SimpleVersionedEntity.class ); - return (MetadataImplementor) sources.buildMetadata(); + public MetadataImpl addSourcesForManyToOne(MetadataSources sources) { + sources.addAnnotatedClass( ManyToOneEntity.class ); + sources.addAnnotatedClass( SimpleEntity.class ); + return (MetadataImpl) sources.buildMetadata(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicHbmBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicHbmBindingTests.java index 847757b73d..927354b15e 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicHbmBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicHbmBindingTests.java @@ -25,9 +25,6 @@ package org.hibernate.metamodel.binding; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.source.internal.MetadataImpl; -import org.hibernate.metamodel.source.spi.MetadataImplementor; - -import static org.junit.Assert.assertEquals; /** * Basic tests of {@code hbm.xml} binding code @@ -35,33 +32,19 @@ import static org.junit.Assert.assertEquals; * @author Steve Ebersole */ public class BasicHbmBindingTests extends AbstractBasicBindingTests { - public EntityBinding buildSimpleEntityBinding() { - return getEntityBinding( - "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml", - SimpleEntity.class.getName() - ); + public MetadataImpl addSourcesForSimpleEntityBinding(MetadataSources sources) { + sources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" ); + return (MetadataImpl) sources.buildMetadata(); } - public EntityBinding buildSimpleVersionedEntityBinding() { - return getEntityBinding( - "org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml", - SimpleVersionedEntity.class.getName() - ); + public MetadataImpl addSourcesForSimpleVersionedEntityBinding(MetadataSources sources) { + sources.addResource( "org/hibernate/metamodel/binding/SimpleVersionedEntity.hbm.xml" ); + return (MetadataImpl) sources.buildMetadata(); } - public MetadataImplementor buildMetadataWithManyToOne() { - MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() ); - metadataSources.addResource( "org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml" ); - metadataSources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" ); - assertEquals( 2, metadataSources.getJaxbRootList().size() ); - return ( MetadataImplementor ) metadataSources.buildMetadata(); - } - - private EntityBinding getEntityBinding(String resourceName, String entityName ) { - MetadataSources metadataSources = new MetadataSources( basicServiceRegistry() ); - metadataSources.addResource( resourceName ); - assertEquals( 1, metadataSources.getJaxbRootList().size() ); - MetadataImpl metadata = ( MetadataImpl ) metadataSources.buildMetadata(); - return metadata.getEntityBinding( entityName ); + public MetadataImpl addSourcesForManyToOne(MetadataSources sources) { + sources.addResource( "org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml" ); + sources.addResource( "org/hibernate/metamodel/binding/SimpleEntity.hbm.xml" ); + return (MetadataImpl) sources.buildMetadata(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml deleted file mode 100644 index e1d9cb8d15..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.hbm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml new file mode 100644 index 0000000000..e0d1af18d7 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.java similarity index 78% rename from hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.java index 18485baad2..7069704cca 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithManyToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/ManyToOneEntity.java @@ -23,9 +23,6 @@ */ package org.hibernate.metamodel.binding; -import java.util.HashSet; -import java.util.Set; - import javax.persistence.Id; import javax.persistence.ManyToOne; @@ -35,17 +32,18 @@ import org.hibernate.annotations.Entity; * @author Gail Badner */ @Entity -public class EntityWithManyToOne { +public class ManyToOneEntity { @Id private Long id; private String theName; + @ManyToOne SimpleEntity simpleEntity; - public EntityWithManyToOne() { + public ManyToOneEntity() { } - public EntityWithManyToOne(String name) { - this.theName = theName; + public ManyToOneEntity(String name) { + this.theName = name; } public Long getId() { @@ -61,10 +59,9 @@ public class EntityWithManyToOne { } public void setName(String name) { - this.theName = theName; + this.theName = name; } - @ManyToOne public SimpleEntity getSimpleEntity() { return simpleEntity; } @@ -72,4 +69,15 @@ public class EntityWithManyToOne { public void setSimpleEntity(SimpleEntity simpleEntity) { this.simpleEntity = simpleEntity; } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append( "EntityWithManyToOne" ); + sb.append( "{id=" ).append( id ); + sb.append( ", theName='" ).append( theName ).append( '\'' ); + sb.append( ", simpleEntity=" ).append( simpleEntity ); + sb.append( '}' ); + return sb.toString(); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/MiscAnnotationBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/MiscAnnotationBindingTest.java index daac49fd64..71ba4f96f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/MiscAnnotationBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/MiscAnnotationBindingTest.java @@ -25,7 +25,7 @@ public class MiscAnnotationBindingTest extends BaseUnitTestCase { sources.addAnnotatedClass( Foo.class ); MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); - EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getSimpleName() + "$" + Foo.class.getSimpleName() ); + EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getName() + "$" + Foo.class.getSimpleName() ); assertEquals( "Wrong where filter", "1=1", binding.getWhereFilter() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/CacheBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/CacheBindingTests.java index db9c06d56c..4c4aeb9405 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/CacheBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/CacheBindingTests.java @@ -65,7 +65,11 @@ public class CacheBindingTests extends BaseUnitTestCase { EntityBinding binding = getEntityBinding( JpaCacheEntity.class, SharedCacheMode.ALL ); assertNotNull( "There should be a cache binding", binding.getCaching() ); Caching caching = binding.getCaching(); - assertEquals( "Wrong region", "CacheBindingTests$JpaCacheEntity", caching.getRegion() ); + assertEquals( + "Wrong region", + this.getClass().getName() + "$" + JpaCacheEntity.class.getSimpleName(), + caching.getRegion() + ); assertEquals( "Wrong lazy properties configuration", true, caching.isCacheLazyProperties() ); } @@ -81,7 +85,7 @@ public class CacheBindingTests extends BaseUnitTestCase { sources.getMetadataBuilder().with( cacheMode ); MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); - return metadata.getEntityBinding( this.getClass().getSimpleName() + "$" + clazz.getSimpleName() ); + return metadata.getEntityBinding( this.getClass().getName() + "$" + clazz.getSimpleName() ); } @Entity 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 ace6963078..8f5738feb0 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 @@ -52,7 +52,7 @@ public class InheritanceTypeTest extends BaseUnitTestCase { @Test public void testDiscriminatorValue() { MetadataImpl meta = buildMetadata( RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class ); - EntityBinding entityBinding = meta.getEntityBinding( SubclassOfSingleTableInheritance.class.getSimpleName() ); + EntityBinding entityBinding = meta.getEntityBinding( SubclassOfSingleTableInheritance.class.getName() ); assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() ); } @@ -65,7 +65,7 @@ public class InheritanceTypeTest extends BaseUnitTestCase { } private EntityBinding getEntityBindingForInnerClass(MetadataImpl meta, Class clazz) { - return meta.getEntityBinding( this.getClass().getSimpleName() + "$" + clazz.getSimpleName() ); + return meta.getEntityBinding( this.getClass().getName() + "$" + clazz.getSimpleName() ); } @Entity