diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/AttributeAccessor.java b/hibernate-core/src/main/java/org/hibernate/annotations/AttributeAccessor.java index 672f17a9f3..f98c27996c 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/AttributeAccessor.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/AttributeAccessor.java @@ -6,6 +6,8 @@ */ package org.hibernate.annotations; +import org.hibernate.property.access.spi.PropertyAccessStrategy; + import java.lang.annotation.Retention; import static java.lang.annotation.ElementType.FIELD; @@ -43,6 +45,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; public @interface AttributeAccessor { /** * Names the {@link org.hibernate.property.access.spi.PropertyAccessStrategy} strategy. + * + * @deprecated use {@link #strategy()} */ - String value(); + @Deprecated + String value() default ""; + /** + * A class implementing {@link org.hibernate.property.access.spi.PropertyAccessStrategy}. + */ + Class strategy() default PropertyAccessStrategy.class; } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java index 6f38a23c2e..729c68fc66 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java @@ -41,6 +41,7 @@ import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; +import org.hibernate.property.access.spi.PropertyAccessStrategy; import org.hibernate.tuple.AnnotationValueGeneration; import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.ValueGeneration; @@ -276,7 +277,17 @@ public class PropertyBinder { if ( property.isAnnotationPresent( AttributeAccessor.class ) ) { final AttributeAccessor accessor = property.getAnnotation( AttributeAccessor.class ); - prop.setPropertyAccessorName( accessor.value() ); + String value = accessor.value(); + Class type = accessor.strategy(); + if ( !value.isEmpty() ) { + prop.setPropertyAccessorName( value ); + } + else if ( !PropertyAccessStrategy.class.equals(type) ) { + prop.setPropertyAccessorName( type.getName() ); + } + else { + throw new AnnotationException("@AttributeAccessor must specify a PropertyAccessStrategy type"); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java index 45f35078a6..6699acad0b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java @@ -83,7 +83,7 @@ public class AttributeAccessorTest { this.id = id; } - @AttributeAccessor("org.hibernate.orm.test.bootstrap.binding.annotations.access.AttributeAccessorTest$BasicAttributeAccessor") + @AttributeAccessor(strategy =BasicAttributeAccessor.class) public String getName() { return name; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/AttributeAccessorTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/AttributeAccessorTest.java index c03e3909aa..3577714b02 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/AttributeAccessorTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/AttributeAccessorTest.java @@ -78,7 +78,7 @@ public class AttributeAccessorTest extends BaseEnversJPAFunctionalTestCase { this.id = id; } - @AttributeAccessor( "org.hibernate.envers.test.integration.accesstype.AttributeAccessorTest$BasicAttributeAccessor" ) + @AttributeAccessor( strategy =BasicAttributeAccessor.class ) public String getName() { return name; }