diff --git a/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc b/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc index 61af303f92..531cc97c70 100644 --- a/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc +++ b/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc @@ -621,12 +621,6 @@ See the <> or the Hibernate native <> annotation. - [[annotations-hibernate-any]] ==== `@Any` diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/AccessType.java b/hibernate-core/src/main/java/org/hibernate/annotations/AccessType.java deleted file mode 100644 index 17413e40de..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/AccessType.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Property Access type. Prefer the standard {@link javax.persistence.Access} annotation; however, - * {@code @Access} is limited to field/property access definitions. - * - * @author Emmanuel Bernard - * - * @deprecated Use {@link AttributeAccessor} instead; renamed to avoid confusion with the JPA - * {@link javax.persistence.AccessType} enum. - */ -@Target({ TYPE, METHOD, FIELD }) -@Retention(RUNTIME) -@Deprecated -public @interface AccessType { - /** - * The access strategy name. - */ - String value(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java index 73e4d03dad..12b5f5bbcf 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java @@ -342,34 +342,10 @@ class PropertyContainer { // } private AccessType determineLocalClassDefinedAccessStrategy() { - AccessType classDefinedAccessType; - - AccessType hibernateDefinedAccessType = AccessType.DEFAULT; - AccessType jpaDefinedAccessType = AccessType.DEFAULT; - - org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class ); - if ( accessType != null ) { - hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() ); - } - + AccessType classDefinedAccessType = AccessType.DEFAULT; Access access = xClass.getAnnotation( Access.class ); if ( access != null ) { - jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() ); - } - - if ( hibernateDefinedAccessType != AccessType.DEFAULT - && jpaDefinedAccessType != AccessType.DEFAULT - && hibernateDefinedAccessType != jpaDefinedAccessType ) { - throw new MappingException( - "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. " - ); - } - - if ( hibernateDefinedAccessType != AccessType.DEFAULT ) { - classDefinedAccessType = hibernateDefinedAccessType; - } - else { - classDefinedAccessType = jpaDefinedAccessType; + classDefinedAccessType = AccessType.getAccessStrategy( access.value() ); } return classDefinedAccessType; } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java index 76233cb2d0..3fd1e56ceb 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyInferredData.java @@ -49,35 +49,14 @@ public class PropertyInferredData implements PropertyData { public AccessType getDefaultAccess() throws MappingException { AccessType accessType = defaultAccess; - AccessType hibernateAccessType = AccessType.DEFAULT; AccessType jpaAccessType = AccessType.DEFAULT; - org.hibernate.annotations.AccessType accessTypeAnnotation = property.getAnnotation( org.hibernate.annotations.AccessType.class ); - if ( accessTypeAnnotation != null ) { - hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() ); - } - Access access = property.getAnnotation( Access.class ); if ( access != null ) { jpaAccessType = AccessType.getAccessStrategy( access.value() ); } - if ( hibernateAccessType != AccessType.DEFAULT - && jpaAccessType != AccessType.DEFAULT - && hibernateAccessType != jpaAccessType ) { - - StringBuilder builder = new StringBuilder(); - builder.append( property.toString() ); - builder.append( - " defines @AccessType and @Access with contradicting values. Use of @Access only is recommended." - ); - throw new MappingException( builder.toString() ); - } - - if ( hibernateAccessType != AccessType.DEFAULT ) { - accessType = hibernateAccessType; - } - else if ( jpaAccessType != AccessType.DEFAULT ) { + if ( jpaAccessType != AccessType.DEFAULT ) { accessType = jpaAccessType; } return accessType; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index ff12ec196c..254c466eec 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -1299,33 +1299,10 @@ public class EntityBinder { public AccessType getExplicitAccessType(XAnnotatedElement element) { AccessType accessType = null; - - AccessType hibernateAccessType = null; - AccessType jpaAccessType = null; - - org.hibernate.annotations.AccessType accessTypeAnnotation = element.getAnnotation( org.hibernate.annotations.AccessType.class ); - if ( accessTypeAnnotation != null ) { - hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() ); - } - Access access = element.getAnnotation( Access.class ); if ( access != null ) { - jpaAccessType = AccessType.getAccessStrategy( access.value() ); + accessType = AccessType.getAccessStrategy( access.value() ); } - - if ( hibernateAccessType != null && jpaAccessType != null && hibernateAccessType != jpaAccessType ) { - throw new MappingException( - "Found @Access and @AccessType with conflicting values on a property in class " + annotatedClass.toString() - ); - } - - if ( hibernateAccessType != null ) { - accessType = hibernateAccessType; - } - else if ( jpaAccessType != null ) { - accessType = jpaAccessType; - } - return accessType; } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/many2one/Address.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/many2one/Address.java index 90f57146e6..e662577bd4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/many2one/Address.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/many2one/Address.java @@ -5,10 +5,11 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.orm.test.annotations.embedded.many2one; +import javax.persistence.AccessType; import javax.persistence.Embeddable; import javax.persistence.ManyToOne; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * TODO : javadoc @@ -16,7 +17,7 @@ import org.hibernate.annotations.AccessType; * @author Steve Ebersole */ @Embeddable -@AccessType("property") +@Access(AccessType.PROPERTY) public class Address { private String line1; private String line2; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/Name.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/Name.java index 5b7b24cfe5..3bd2774db0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/Name.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/Name.java @@ -5,9 +5,10 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.orm.test.annotations.embedded.one2many; +import javax.persistence.AccessType; import javax.persistence.Embeddable; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * TODO : javadoc @@ -15,7 +16,7 @@ import org.hibernate.annotations.AccessType; * @author Steve Ebersole */ @Embeddable -@AccessType("property") +@Access(AccessType.PROPERTY) public class Name { private String first; private String last; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/PersonName.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/PersonName.java index f7924b98c6..7b044b0fd8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/PersonName.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embedded/one2many/PersonName.java @@ -7,11 +7,12 @@ package org.hibernate.orm.test.annotations.embedded.one2many; import java.util.HashSet; import java.util.Set; +import javax.persistence.AccessType; import javax.persistence.CascadeType; import javax.persistence.Embeddable; import javax.persistence.OneToMany; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * TODO : javadoc @@ -19,7 +20,7 @@ import org.hibernate.annotations.AccessType; * @author Steve Ebersole */ @Embeddable -@AccessType("property") +@Access(AccessType.PROPERTY) public class PersonName extends Name { private Set aliases = new HashSet(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/BaseFurniture.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/BaseFurniture.java index aca37a3be7..6fce0270ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/BaseFurniture.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/BaseFurniture.java @@ -8,12 +8,13 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.access; +import javax.persistence.AccessType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Transient; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * @author Vlad Mihalcea @@ -43,7 +44,7 @@ public class BaseFurniture extends Woody { this.id = id; } - @AccessType("property") + @Access(AccessType.PROPERTY) public long weight; public long getWeight() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Bed.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Bed.java index 6dd0603ac2..d99ae059de 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Bed.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Bed.java @@ -7,16 +7,17 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.access; +import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.Transient; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * @author Emmanuel Bernard */ @Entity -@AccessType("property") +@Access(AccessType.PROPERTY) public class Bed extends Furniture { String quality; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Furniture.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Furniture.java index ad9ffafacc..85293ad09d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Furniture.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Furniture.java @@ -7,15 +7,16 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.access; +import javax.persistence.AccessType; import javax.persistence.Entity; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * @author Emmanuel Bernard */ @Entity -@AccessType("field") +@Access(AccessType.FIELD) public class Furniture extends BaseFurniture { } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Gardenshed.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Gardenshed.java index bccb359e72..65b5436a26 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Gardenshed.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Gardenshed.java @@ -7,22 +7,24 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.access; + +import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Transient; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** - * This is the opposite of the Furniture test, as this tries to override the class AccessType("property") with - * the property AccessType("field"). + * This is the opposite of the Furniture test, as this tries to override the class Access(AccessType.PROPERTY) with + * the property Access(AccessType.FIELD). * * @author Dennis Fleurbaaij * @since 2007-05-31 */ @Entity -@AccessType( "property" ) +@Access(javax.persistence.AccessType.PROPERTY) public class Gardenshed extends Woody { @@ -50,7 +52,7 @@ public class Gardenshed } // These 2 functions should not return in Hibernate, but the value should come from the field "floors" - @AccessType( "field" ) + @Access(AccessType.FIELD) public long getFloors() { return this.floors + 2; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Woody.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Woody.java index 3d470c1edf..36808e7a4a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Woody.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/Woody.java @@ -7,15 +7,16 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.access; +import javax.persistence.AccessType; import javax.persistence.MappedSuperclass; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * @author Emmanuel Bernard */ @MappedSuperclass -@AccessType("property") +@Access(AccessType.PROPERTY) public class Woody extends Thingy { private String color; private String name; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Course3.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Course3.java index 80da63f382..4f282b9969 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Course3.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Course3.java @@ -33,7 +33,7 @@ public class Course3 { @Id @GeneratedValue - @org.hibernate.annotations.AccessType("field") + @Access(AccessType.FIELD) public long getId() { return id; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Gardenshed.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Gardenshed.java index af27285cbf..aa58e33b8b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Gardenshed.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/jpa/Gardenshed.java @@ -15,8 +15,8 @@ import javax.persistence.Id; import javax.persistence.Transient; /** - * This is the opposite of the Furniture test, as this tries to override the class AccessType("property") with - * the property AccessType("field"). + * This is the opposite of the Furniture test, as this tries to override the class Access(AccessType.PROPERTY) with + * the property Access(AccessType.FIELD). * * @author Dennis Fleurbaaij * @since 2007-05-31 diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/Country.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/Country.java index c5e038790c..56d73a5721 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/Country.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/Country.java @@ -8,10 +8,11 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.embedded; import java.io.Serializable; +import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Embeddable; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * Non realistic embedded dependent object @@ -19,7 +20,7 @@ import org.hibernate.annotations.AccessType; * @author Emmanuel Bernard */ @Embeddable -@AccessType("property") +@Access(AccessType.PROPERTY) public class Country implements Serializable { private String iso2; private String name; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/RegionalArticlePk.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/RegionalArticlePk.java index e1aad1dfc8..9466ac30a4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/RegionalArticlePk.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/RegionalArticlePk.java @@ -8,9 +8,10 @@ //$Id$ package org.hibernate.orm.test.bootstrap.binding.annotations.embedded; import java.io.Serializable; +import javax.persistence.AccessType; import javax.persistence.Embeddable; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * Regional article pk @@ -18,7 +19,7 @@ import org.hibernate.annotations.AccessType; * @author Emmanuel Bernard */ @Embeddable -@AccessType("field") +@Access(AccessType.FIELD) public class RegionalArticlePk implements Serializable { /** * country iso2 code diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Student.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Student.java index db4e69b157..875264edcd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Student.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Student.java @@ -6,6 +6,7 @@ */ package org.hibernate.orm.test.jpa.cascade; +import javax.persistence.AccessType; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -13,10 +14,10 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; @Entity -@AccessType("field") +@Access(AccessType.FIELD) public class Student { @Id @GeneratedValue diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Teacher.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Teacher.java index 8aa16012a2..5eddd7e016 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Teacher.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/Teacher.java @@ -8,6 +8,7 @@ package org.hibernate.orm.test.jpa.cascade; import java.util.HashSet; import java.util.Set; +import javax.persistence.AccessType; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -15,10 +16,10 @@ import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; @Entity -@AccessType("field") +@Access(AccessType.FIELD) public class Teacher { @Id @GeneratedValue diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LGMB_To.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LGMB_To.java index 6f67c6b0a4..a0598f2f61 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LGMB_To.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LGMB_To.java @@ -1,5 +1,6 @@ package org.hibernate.test.bytecode.enhancement.lazy.group; +import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,7 +9,7 @@ import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; /** * Target of a LazyToOne - relationship (Foreignkey on this side) @@ -22,7 +23,7 @@ public class LGMB_To { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(nullable = false) - @AccessType("property") + @Access(AccessType.PROPERTY) private Long id; @OneToOne diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java index b3bf8f4e09..d17273ed3b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/accesstype/MixedAccessTypeEntity.java @@ -6,12 +6,13 @@ */ package org.hibernate.envers.test.integration.accesstype; +import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Transient; -import org.hibernate.annotations.AccessType; +import javax.persistence.Access; import org.hibernate.envers.Audited; /** @@ -23,7 +24,7 @@ public class MixedAccessTypeEntity { @GeneratedValue private Integer id; - @AccessType("property") + @Access(AccessType.PROPERTY) private String data; @Transient