From 2b17b95980297c0c4537ae92bc56b5ea6dede244 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 25 Mar 2014 22:08:10 -0500 Subject: [PATCH] FailureExpectedWithNewMetamodel cleanup --- .../metamodel/internal/binder/Binder.java | 6 ++-- .../AbstractPersistentAttribute.java | 9 +++++ .../entity/ManagedTypeMetadata.java | 12 ++----- .../annotations/entity/CacheBindingTest.java | 8 ++--- .../AbstractComponentPropertyRefTest.java | 6 ++-- .../test/annotations/JoinedSubclassTest.java | 9 +++-- .../annotations/inheritance/Vegetable.java | 2 +- .../annotations/inheritance/VegetablePk.java | 36 +++++++++---------- 8 files changed, 42 insertions(+), 46 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java index ab19cf95b0..0724fc0d9e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/Binder.java @@ -61,6 +61,7 @@ import org.hibernate.id.PersistentIdentifierGenerator; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.internal.FilterConfiguration; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.internal.binder.HibernateTypeHelper.ReflectedCollectionJavaTypes; import org.hibernate.metamodel.internal.resolver.AssociationRelationalBindingResolver; import org.hibernate.metamodel.internal.resolver.MappedByAssociationRelationalBindingResolverImpl; @@ -1569,10 +1570,7 @@ public class Binder { } } else { - joinRelationalValueBindings = new ArrayList( - joinedPrimaryKeyColumnSources - .size() - ); + joinRelationalValueBindings = CollectionHelper.arrayList( joinedPrimaryKeyColumnSources.size() ); if ( primaryKeyColumns.size() != joinedPrimaryKeyColumnSources.size() ) { throw localBindingContext().makeMappingException( String.format( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java index dd2b366276..d63fa8adde 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/attribute/AbstractPersistentAttribute.java @@ -44,6 +44,7 @@ import org.hibernate.metamodel.spi.NaturalIdMutability; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; +import org.jboss.logging.Logger; /** * Base class for the different types of persistent attributes @@ -52,6 +53,8 @@ import org.jboss.jandex.AnnotationValue; * @author Hardy Ferentschik */ public abstract class AbstractPersistentAttribute implements PersistentAttribute { + private static final Logger log = Logger.getLogger( AbstractPersistentAttribute.class ); + private final ManagedTypeMetadata container; private final String attributeName; private final AttributePath attributePath; @@ -163,6 +166,12 @@ public abstract class AbstractPersistentAttribute implements PersistentAttribute final AnnotationInstance idAnnotation = backingMember.getAnnotations().get( JPADotNames.ID ); if ( idAnnotation != null ) { validatePresenceOfIdAnnotation(); + if ( backingMember.getType().getErasedType().findTypeAnnotation( JPADotNames.EMBEDDABLE ) != null ) { + log.warn( + "Attribute was annotated with @Id, but attribute type was annotated as @Embeddable; " + + "did you mean to use @EmbeddedId on the attribute rather than @Id?" + ); + } return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java index 57e1fc5185..f3c88ccd8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/entity/ManagedTypeMetadata.java @@ -42,7 +42,6 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.reflite.internal.ModifierUtils; -import org.hibernate.metamodel.reflite.spi.ArrayDescriptor; import org.hibernate.metamodel.reflite.spi.ClassDescriptor; import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; @@ -973,10 +972,10 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect if ( isEmbeddableType( attributeType ) ) { LOG.warnf( "Class %s was annotated as @Embeddable. However a persistent attribute [%s] " + - "of this type was found that did not contain the @Embedded annotation. " + + "of this type was found that did not contain the @Embedded (or @EmbeddedId) annotation. " + "This may cause compatibility issues", attributeType.getName(), - member.toString() + member.toLoggableForm() ); categories.add( AttributeCategorization.EMBEDDED ); } @@ -1042,13 +1041,6 @@ public abstract class ManagedTypeMetadata implements OverrideAndConverterCollect } - @SuppressWarnings("RedundantIfStatement") - private boolean isCollectionOrArray(JavaTypeDescriptor attributeType) { - return ArrayDescriptor.class.isInstance( attributeType ) - || getLocalBindingContext().getJavaTypeDescriptorRepository().jdkMapDescriptor().isAssignableFrom( attributeType ) - || getLocalBindingContext().getJavaTypeDescriptorRepository().jdkCollectionDescriptor().isAssignableFrom( attributeType ); - } - protected boolean isEmbeddableType(JavaTypeDescriptor descriptor) { return descriptor.findTypeAnnotation( JPADotNames.EMBEDDABLE ) != null; } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/CacheBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/CacheBindingTest.java index 279d3a77a6..0a75a66793 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/CacheBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/CacheBindingTest.java @@ -35,7 +35,6 @@ import org.hibernate.cache.spi.access.AccessType; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.EntityBinding; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase; import org.hibernate.testing.junit4.Resources; import org.junit.Test; @@ -43,7 +42,6 @@ import org.junit.Test; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; -import static org.junit.Assert.assertFalse; /** * Tests for {@code o.h.a.Cache} and {@code j.p.Cacheable}. @@ -77,12 +75,12 @@ public class CacheBindingTest extends BaseAnnotationBindingTestCase { @Test @Resources(annotatedClasses = NoCacheEntity.class, cacheMode = SharedCacheMode.NONE) - @FailureExpectedWithNewMetamodel( message = "I am not so sure that bindings/metamodel is the right place to deal with SharedCacheMode" ) public void testNoCaching() { EntityBinding binding = getEntityBinding( NoCacheEntity.class ); - assertFalse( + assertEquals( "There should be no cache binding", - binding.getHierarchyDetails().getCaching().getRequested() != TruthValue.TRUE + TruthValue.FALSE, + binding.getHierarchyDetails().getCaching().getRequested() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/abstractembeddedcomponents/propertyref/AbstractComponentPropertyRefTest.java b/hibernate-core/src/test/java/org/hibernate/test/abstractembeddedcomponents/propertyref/AbstractComponentPropertyRefTest.java index cf86ab64c5..2e1a66619a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/abstractembeddedcomponents/propertyref/AbstractComponentPropertyRefTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/abstractembeddedcomponents/propertyref/AbstractComponentPropertyRefTest.java @@ -23,25 +23,25 @@ */ package org.hibernate.test.abstractembeddedcomponents.propertyref; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.Transaction; + import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class AbstractComponentPropertyRefTest extends BaseCoreFunctionalTestCase { public String[] getMappings() { return new String[] { "abstractembeddedcomponents/propertyref/Mappings.hbm.xml" }; } @Test + @FailureExpectedWithNewMetamodel( jiraKey = "HHH-7242", message = "property-ref" ) public void testPropertiesRefCascades() { Session session = openSession(); Transaction trans = session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/JoinedSubclassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/JoinedSubclassTest.java index add4ce9d03..b93230ebc5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/JoinedSubclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/JoinedSubclassTest.java @@ -23,16 +23,15 @@ */ package org.hibernate.test.annotations; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.Transaction; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.test.annotations.inheritance.Carrot; import org.hibernate.test.annotations.inheritance.Tomato; import org.hibernate.test.annotations.inheritance.Vegetable; import org.hibernate.test.annotations.inheritance.VegetablePk; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -41,7 +40,6 @@ import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class JoinedSubclassTest extends BaseCoreFunctionalTestCase { @Test public void testDefaultValues() { @@ -129,6 +127,7 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase { AmericaCupClass.class, Country.class, Vegetable.class, + VegetablePk.class, Carrot.class, Tomato.class }; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/Vegetable.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/Vegetable.java index e64a1559f5..59ceaa6f0e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/Vegetable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/Vegetable.java @@ -1,5 +1,5 @@ -//$Id$ package org.hibernate.test.annotations.inheritance; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Inheritance; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/VegetablePk.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/VegetablePk.java index de7bd8d687..84abb65d15 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/VegetablePk.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/inheritance/VegetablePk.java @@ -1,5 +1,5 @@ -//$Id$ package org.hibernate.test.annotations.inheritance; + import java.io.Serializable; import javax.persistence.Embeddable; @@ -9,6 +9,23 @@ import javax.persistence.Embeddable; @Embeddable public class VegetablePk implements Serializable { private String farmer; + private String harvestDate; + + public String getFarmer() { + return farmer; + } + + public void setFarmer(String farmer) { + this.farmer = farmer; + } + + public String getHarvestDate() { + return harvestDate; + } + + public void setHarvestDate(String harvestDate) { + this.harvestDate = harvestDate; + } public boolean equals(Object o) { if ( this == o ) return true; @@ -29,21 +46,4 @@ public class VegetablePk implements Serializable { return result; } - public String getFarmer() { - return farmer; - } - - public void setFarmer(String farmer) { - this.farmer = farmer; - } - - public String getHarvestDate() { - return harvestDate; - } - - public void setHarvestDate(String harvestDate) { - this.harvestDate = harvestDate; - } - - private String harvestDate; }