remove AccessType annotation

This commit is contained in:
Gavin King 2021-02-25 10:57:51 +01:00
parent 4b56842c7f
commit c89319f3e9
21 changed files with 53 additions and 146 deletions

View File

@ -621,12 +621,6 @@ See the <<chapters/locking/Locking.adoc#locking-optimistic, Optimistic locking m
[[annotations-hibernate]] [[annotations-hibernate]]
=== Hibernate annotations === Hibernate annotations
[[annotations-hibernate-accesstype]]
==== [line-through]#`@AccessType`#
The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/annotations/AccessType.html[[line-through]#`@AccessType`#] annotation is deprecated.
You should use either the JPA <<annotations-jpa-access>> or the Hibernate native <<annotations-hibernate-attributeaccessor>> annotation.
[[annotations-hibernate-any]] [[annotations-hibernate-any]]
==== `@Any` ==== `@Any`

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}

View File

@ -342,34 +342,10 @@ class PropertyContainer {
// } // }
private AccessType determineLocalClassDefinedAccessStrategy() { private AccessType determineLocalClassDefinedAccessStrategy() {
AccessType classDefinedAccessType; AccessType classDefinedAccessType = AccessType.DEFAULT;
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() );
}
Access access = xClass.getAnnotation( Access.class ); Access access = xClass.getAnnotation( Access.class );
if ( access != null ) { if ( access != null ) {
jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() ); classDefinedAccessType = 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;
} }
return classDefinedAccessType; return classDefinedAccessType;
} }

View File

@ -49,35 +49,14 @@ public class PropertyInferredData implements PropertyData {
public AccessType getDefaultAccess() throws MappingException { public AccessType getDefaultAccess() throws MappingException {
AccessType accessType = defaultAccess; AccessType accessType = defaultAccess;
AccessType hibernateAccessType = AccessType.DEFAULT;
AccessType jpaAccessType = 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 ); Access access = property.getAnnotation( Access.class );
if ( access != null ) { if ( access != null ) {
jpaAccessType = AccessType.getAccessStrategy( access.value() ); jpaAccessType = AccessType.getAccessStrategy( access.value() );
} }
if ( hibernateAccessType != AccessType.DEFAULT if ( jpaAccessType != 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 ) {
accessType = jpaAccessType; accessType = jpaAccessType;
} }
return accessType; return accessType;

View File

@ -1299,33 +1299,10 @@ public class EntityBinder {
public AccessType getExplicitAccessType(XAnnotatedElement element) { public AccessType getExplicitAccessType(XAnnotatedElement element) {
AccessType accessType = null; 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 ); Access access = element.getAnnotation( Access.class );
if ( access != null ) { 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; return accessType;
} }
} }

View File

@ -5,10 +5,11 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.orm.test.annotations.embedded.many2one; package org.hibernate.orm.test.annotations.embedded.many2one;
import javax.persistence.AccessType;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* TODO : javadoc * TODO : javadoc
@ -16,7 +17,7 @@ import org.hibernate.annotations.AccessType;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@Embeddable @Embeddable
@AccessType("property") @Access(AccessType.PROPERTY)
public class Address { public class Address {
private String line1; private String line1;
private String line2; private String line2;

View File

@ -5,9 +5,10 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.orm.test.annotations.embedded.one2many; package org.hibernate.orm.test.annotations.embedded.one2many;
import javax.persistence.AccessType;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* TODO : javadoc * TODO : javadoc
@ -15,7 +16,7 @@ import org.hibernate.annotations.AccessType;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@Embeddable @Embeddable
@AccessType("property") @Access(AccessType.PROPERTY)
public class Name { public class Name {
private String first; private String first;
private String last; private String last;

View File

@ -7,11 +7,12 @@
package org.hibernate.orm.test.annotations.embedded.one2many; package org.hibernate.orm.test.annotations.embedded.one2many;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.AccessType;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* TODO : javadoc * TODO : javadoc
@ -19,7 +20,7 @@ import org.hibernate.annotations.AccessType;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@Embeddable @Embeddable
@AccessType("property") @Access(AccessType.PROPERTY)
public class PersonName extends Name { public class PersonName extends Name {
private Set<Alias> aliases = new HashSet<Alias>(); private Set<Alias> aliases = new HashSet<Alias>();

View File

@ -8,12 +8,13 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.access; package org.hibernate.orm.test.bootstrap.binding.annotations.access;
import javax.persistence.AccessType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
@ -43,7 +44,7 @@ public class BaseFurniture extends Woody {
this.id = id; this.id = id;
} }
@AccessType("property") @Access(AccessType.PROPERTY)
public long weight; public long weight;
public long getWeight() { public long getWeight() {

View File

@ -7,16 +7,17 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.access; package org.hibernate.orm.test.bootstrap.binding.annotations.access;
import javax.persistence.AccessType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@AccessType("property") @Access(AccessType.PROPERTY)
public class Bed extends Furniture { public class Bed extends Furniture {
String quality; String quality;

View File

@ -7,15 +7,16 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.access; package org.hibernate.orm.test.bootstrap.binding.annotations.access;
import javax.persistence.AccessType;
import javax.persistence.Entity; import javax.persistence.Entity;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@AccessType("field") @Access(AccessType.FIELD)
public class Furniture extends BaseFurniture { public class Furniture extends BaseFurniture {
} }

View File

@ -7,22 +7,24 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.access; package org.hibernate.orm.test.bootstrap.binding.annotations.access;
import javax.persistence.AccessType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Transient; 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 * This is the opposite of the Furniture test, as this tries to override the class Access(AccessType.PROPERTY) with
* the property AccessType("field"). * the property Access(AccessType.FIELD).
* *
* @author Dennis Fleurbaaij * @author Dennis Fleurbaaij
* @since 2007-05-31 * @since 2007-05-31
*/ */
@Entity @Entity
@AccessType( "property" ) @Access(javax.persistence.AccessType.PROPERTY)
public class Gardenshed public class Gardenshed
extends extends
Woody { 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" // 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() { public long getFloors() {
return this.floors + 2; return this.floors + 2;
} }

View File

@ -7,15 +7,16 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.access; package org.hibernate.orm.test.bootstrap.binding.annotations.access;
import javax.persistence.AccessType;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@MappedSuperclass @MappedSuperclass
@AccessType("property") @Access(AccessType.PROPERTY)
public class Woody extends Thingy { public class Woody extends Thingy {
private String color; private String color;
private String name; private String name;

View File

@ -33,7 +33,7 @@ public class Course3 {
@Id @Id
@GeneratedValue @GeneratedValue
@org.hibernate.annotations.AccessType("field") @Access(AccessType.FIELD)
public long getId() { public long getId() {
return id; return id;
} }

View File

@ -15,8 +15,8 @@ import javax.persistence.Id;
import javax.persistence.Transient; import javax.persistence.Transient;
/** /**
* This is the opposite of the Furniture test, as this tries to override the class AccessType("property") with * This is the opposite of the Furniture test, as this tries to override the class Access(AccessType.PROPERTY) with
* the property AccessType("field"). * the property Access(AccessType.FIELD).
* *
* @author Dennis Fleurbaaij * @author Dennis Fleurbaaij
* @since 2007-05-31 * @since 2007-05-31

View File

@ -8,10 +8,11 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.embedded; package org.hibernate.orm.test.bootstrap.binding.annotations.embedded;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.AccessType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* Non realistic embedded dependent object * Non realistic embedded dependent object
@ -19,7 +20,7 @@ import org.hibernate.annotations.AccessType;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Embeddable @Embeddable
@AccessType("property") @Access(AccessType.PROPERTY)
public class Country implements Serializable { public class Country implements Serializable {
private String iso2; private String iso2;
private String name; private String name;

View File

@ -8,9 +8,10 @@
//$Id$ //$Id$
package org.hibernate.orm.test.bootstrap.binding.annotations.embedded; package org.hibernate.orm.test.bootstrap.binding.annotations.embedded;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.AccessType;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* Regional article pk * Regional article pk
@ -18,7 +19,7 @@ import org.hibernate.annotations.AccessType;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Embeddable @Embeddable
@AccessType("field") @Access(AccessType.FIELD)
public class RegionalArticlePk implements Serializable { public class RegionalArticlePk implements Serializable {
/** /**
* country iso2 code * country iso2 code

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.orm.test.jpa.cascade; package org.hibernate.orm.test.jpa.cascade;
import javax.persistence.AccessType;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -13,10 +14,10 @@ import javax.persistence.Id;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
@Entity @Entity
@AccessType("field") @Access(AccessType.FIELD)
public class Student { public class Student {
@Id @GeneratedValue @Id @GeneratedValue

View File

@ -8,6 +8,7 @@ package org.hibernate.orm.test.jpa.cascade;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.AccessType;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -15,10 +16,10 @@ import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
@Entity @Entity
@AccessType("field") @Access(AccessType.FIELD)
public class Teacher { public class Teacher {
@Id @GeneratedValue @Id @GeneratedValue

View File

@ -1,5 +1,6 @@
package org.hibernate.test.bytecode.enhancement.lazy.group; package org.hibernate.test.bytecode.enhancement.lazy.group;
import javax.persistence.AccessType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -8,7 +9,7 @@ import javax.persistence.Id;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
/** /**
* Target of a LazyToOne - relationship (Foreignkey on this side) * Target of a LazyToOne - relationship (Foreignkey on this side)
@ -22,7 +23,7 @@ public class LGMB_To {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false) @Column(nullable = false)
@AccessType("property") @Access(AccessType.PROPERTY)
private Long id; private Long id;
@OneToOne @OneToOne

View File

@ -6,12 +6,13 @@
*/ */
package org.hibernate.envers.test.integration.accesstype; package org.hibernate.envers.test.integration.accesstype;
import javax.persistence.AccessType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.hibernate.annotations.AccessType; import javax.persistence.Access;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
/** /**
@ -23,7 +24,7 @@ public class MixedAccessTypeEntity {
@GeneratedValue @GeneratedValue
private Integer id; private Integer id;
@AccessType("property") @Access(AccessType.PROPERTY)
private String data; private String data;
@Transient @Transient