From 70221d8ac2172da992982f564195b8d3aef7d57b Mon Sep 17 00:00:00 2001 From: brmeyer Date: Tue, 30 Oct 2012 15:24:31 -0400 Subject: [PATCH] HHH-7739 Correct "appliesTo" value handeling on @Table/@Index processing --- .../annotations/global/TableProcessor.java | 6 ++-- .../test/annotations/entity/Forest.java | 16 +++++++---- ...NewCustomEntityMappingAnnotationsTest.java | 28 +++++++++---------- .../org/hibernate/test/util/SchemaUtil.java | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java index f647ec5527..72371d5bae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/TableProcessor.java @@ -93,7 +93,7 @@ public class TableProcessor { "indexes", AnnotationInstance[].class ) ) { - bindIndexAnnotation( table, indexAnnotation ); + bindIndexAnnotation( table, tableAnnotation, indexAnnotation ); } String comment = JandexHelper.getValue( tableAnnotation, "comment", String.class ); if ( StringHelper.isNotEmpty( comment ) ) { @@ -101,8 +101,8 @@ public class TableProcessor { } } - private static void bindIndexAnnotation(Table table, AnnotationInstance indexAnnotation) { - String indexName = JandexHelper.getValue( indexAnnotation, "appliesTo", String.class ); + private static void bindIndexAnnotation(Table table, AnnotationInstance tableAnnotation, AnnotationInstance indexAnnotation) { + String indexName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class ); String[] columnNames = JandexHelper.getValue( indexAnnotation, "columnNames", String[].class ); if ( columnNames == null ) { LOG.noColumnsSpecifiedForIndex( indexName, table.toLoggableString() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/Forest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/Forest.java index e3086ddc21..a142fe29b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/Forest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/Forest.java @@ -1,6 +1,7 @@ //$Id$ package org.hibernate.test.annotations.entity; import java.util.Set; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,15 +9,20 @@ import javax.persistence.Id; import javax.persistence.Lob; import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.Filter; import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.Filters; import org.hibernate.annotations.Index; import org.hibernate.annotations.OptimisticLock; import org.hibernate.annotations.OptimisticLockType; +import org.hibernate.annotations.OptimisticLocking; import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.Polymorphism; import org.hibernate.annotations.PolymorphismType; +import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Type; import org.hibernate.annotations.Where; @@ -27,11 +33,11 @@ import org.hibernate.annotations.Where; */ @Entity @BatchSize(size = 5) -@org.hibernate.annotations.Entity( - selectBeforeUpdate = true, - dynamicInsert = true, dynamicUpdate = true, - optimisticLock = OptimisticLockType.ALL, - polymorphism = PolymorphismType.EXPLICIT) +@SelectBeforeUpdate +@DynamicInsert +@DynamicUpdate +@OptimisticLocking( type = OptimisticLockType.ALL ) +@Polymorphism( type = PolymorphismType.EXPLICIT ) @Where(clause = "1=1") @FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = "integer")}) @Filters({ diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java index 52b9fce443..11b27d1793 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java @@ -23,18 +23,16 @@ */ package org.hibernate.test.annotations.entity; -import org.junit.Test; - -import org.hibernate.mapping.RootClass; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - import static org.junit.Assert.assertEquals; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.test.util.SchemaUtil; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class NewCustomEntityMappingAnnotationsTest extends BaseCoreFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { @@ -48,14 +46,14 @@ public class NewCustomEntityMappingAnnotationsTest extends BaseCoreFunctionalTes @Test public void testSameMappingValues() { - // TODO: These need to use the new metamodel, but the information + EntityBinding forest = SchemaUtil.getEntityBinding( Forest.class, metadata() ); + EntityBinding forest2 = SchemaUtil.getEntityBinding( Forest2.class, metadata() ); + assertEquals( forest.isDynamicInsert(), forest2.isDynamicInsert() ); + assertEquals( forest.isDynamicUpdate(), forest2.isDynamicUpdate() ); + assertEquals( forest.isSelectBeforeUpdate(), forest2.isSelectBeforeUpdate() ); + // TODO: This needs to use the new metamodel, but the information // is not available in EntityBinding. - RootClass forest = (RootClass) configuration().getClassMapping( Forest.class.getName() ); - RootClass forest2 = (RootClass) configuration().getClassMapping( Forest2.class.getName() ); - assertEquals( forest.useDynamicInsert(), forest2.useDynamicInsert() ); - assertEquals( forest.useDynamicUpdate(), forest2.useDynamicUpdate() ); - assertEquals( forest.hasSelectBeforeUpdate(), forest2.hasSelectBeforeUpdate() ); - assertEquals( forest.getOptimisticLockMode(), forest2.getOptimisticLockMode() ); - assertEquals( forest.isExplicitPolymorphism(), forest2.isExplicitPolymorphism() ); +// assertEquals( forest.getOptimisticLockMode(), forest2.getOptimisticLockMode() ); + assertEquals( forest.isPolymorphic(), forest2.isPolymorphic() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java index 0c44e8b7ec..03e834e7a5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java @@ -60,7 +60,7 @@ public abstract class SchemaUtil { } } - private static EntityBinding getEntityBinding( + public static EntityBinding getEntityBinding( Class entityClass, Metadata metadata ) { return metadata.getEntityBinding( entityClass.getName() ); }