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]]
=== 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]]
==== `@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() {
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;
}

View File

@ -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;

View File

@ -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;
}
}

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>.
*/
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;

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>.
*/
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;

View File

@ -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<Alias> aliases = new HashSet<Alias>();

View File

@ -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() {

View File

@ -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;

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;

View File

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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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