diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/ConfiguredClassHierarchy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/ConfiguredClassHierarchy.java index 533a1188a8..6258af187d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/ConfiguredClassHierarchy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/ConfiguredClassHierarchy.java @@ -202,7 +202,7 @@ public class ConfiguredClassHierarchy implements Iterable { int count = 0; for ( ClassInfo info : classes ) { builder.append( info.name().toString() ); - if ( count < classes.size() ) { + if ( count < classes.size() - 1 ) { builder.append( ", " ); } count++; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityBinder.java index bf1745b94c..031710a896 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityBinder.java @@ -59,6 +59,7 @@ public class EntityBinder { EntityBinding entityBinding = new EntityBinding(); bindJpaEntityAnnotation( entityBinding ); bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity + bindWhereFilter( entityBinding ); schemaName = createSchemaName(); bindTable( entityBinding ); @@ -70,6 +71,17 @@ public class EntityBinder { meta.addEntity( entityBinding ); } + private void bindWhereFilter(EntityBinding entityBinding) { + AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation( + configuredClass.getClassInfo(), HibernateDotNames.WHERE + ); + if ( whereAnnotation != null ) { + // no null check needed, it is a required attribute + String clause = whereAnnotation.value( "clause" ).asString(); + entityBinding.setWhereFilter( clause ); + } + } + private Schema.Name createSchemaName() { String schema = null; String catalog = null; 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 new file mode 100644 index 0000000000..daac49fd64 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/MiscAnnotationBindingTest.java @@ -0,0 +1,40 @@ +package org.hibernate.metamodel.binding; + +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.junit.Test; + +import org.hibernate.annotations.Where; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.source.internal.MetadataImpl; +import org.hibernate.service.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static junit.framework.Assert.assertEquals; + +/** + * @author Hardy Ferentschik + */ +public class MiscAnnotationBindingTest extends BaseUnitTestCase { + @Test + public void testWhereFilter() { + + + MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); + sources.addAnnotatedClass( Foo.class ); + MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); + + EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getSimpleName() + "$" + Foo.class.getSimpleName() ); + assertEquals( "Wrong where filter", "1=1", binding.getWhereFilter() ); + } + + @Entity + @Where(clause = "1=1") + class Foo { + @Id + private long id; + } +} + +