remove deprecated @Entity annotation

This commit is contained in:
Gavin King 2021-02-25 11:22:43 +01:00
parent 50363dcc2c
commit 3b3487a74e
18 changed files with 42 additions and 151 deletions

View File

@ -773,11 +773,6 @@ See the <<chapters/pc/PersistenceContext.adoc#pc-managed-state-dynamic-update,`@
For reattachment of detached entities, the dynamic update is not possible without having the <<annotations-hibernate-selectbeforeupdate>> annotation as well. For reattachment of detached entities, the dynamic update is not possible without having the <<annotations-hibernate-selectbeforeupdate>> annotation as well.
==== ====
[[annotations-hibernate-entity]]
==== [line-through]#`@Entity`#
The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/annotations/Entity.html[[line-through]#`@Entity`#] annotation is deprecated. Use the JPA <<annotations-jpa-entity>> annotation instead.
[[annotations-hibernate-fetch]] [[annotations-hibernate-fetch]]
==== `@Fetch` ==== `@Fetch`

View File

@ -1,69 +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.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Extends {@link javax.persistence.Entity} with Hibernate features.
*
* @author Emmanuel Bernard
*
* @deprecated See individual attributes for intended replacements. To be removed in 4.1
*/
@Target(TYPE)
@Retention(RUNTIME)
@Deprecated
public @interface Entity {
/**
* Is this entity mutable (read only) or not.
*
* @deprecated use {@link org.hibernate.annotations.Immutable}
*/
@Deprecated
boolean mutable() default true;
/**
* Needed column only in SQL on insert.
* @deprecated use {@link DynamicInsert} instead
*/
@Deprecated
boolean dynamicInsert() default false;
/**
* Needed column only in SQL on update.
* @deprecated Use {@link DynamicUpdate} instead
*/
@Deprecated
boolean dynamicUpdate() default false;
/**
* Do a select to retrieve the entity before any potential update.
* @deprecated Use {@link SelectBeforeUpdate} instead
*/
@Deprecated
boolean selectBeforeUpdate() default false;
/**
* polymorphism strategy for this entity.
* @deprecated use {@link Polymorphism} instead
*/
@Deprecated
PolymorphismType polymorphism() default PolymorphismType.IMPLICIT;
/**
* optimistic locking strategy.
* @deprecated use {@link OptimisticLocking} instead.
*/
@Deprecated
OptimisticLockType optimisticLock() default OptimisticLockType.VERSION;
/**
* persister of this entity, default is hibernate internal one.
* @deprecated use {@link Persister} instead
*/
@Deprecated
String persister() default "";
}

View File

@ -605,12 +605,8 @@ public final class AnnotationBinder {
PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context ); PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context );
Entity entityAnn = clazzToProcess.getAnnotation( Entity.class ); Entity entityAnn = clazzToProcess.getAnnotation( Entity.class );
org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation(
org.hibernate.annotations.Entity.class
);
EntityBinder entityBinder = new EntityBinder( EntityBinder entityBinder = new EntityBinder(
entityAnn, entityAnn,
hibEntityAnn,
clazzToProcess, clazzToProcess,
persistentClass, persistentClass,
context context
@ -1346,10 +1342,6 @@ public final class AnnotationBinder {
|| AnnotatedClassType.NONE.equals( classType ) //to be ignored || AnnotatedClassType.NONE.equals( classType ) //to be ignored
|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration || AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
) { ) {
if ( AnnotatedClassType.NONE.equals( classType )
&& clazzToProcess.isAnnotationPresent( org.hibernate.annotations.Entity.class ) ) {
LOG.missingEntityAnnotation( clazzToProcess.getName() );
}
return false; return false;
} }

View File

@ -117,7 +117,6 @@ public class EntityBinder {
private Boolean insertableDiscriminator; private Boolean insertableDiscriminator;
private boolean dynamicInsert; private boolean dynamicInsert;
private boolean dynamicUpdate; private boolean dynamicUpdate;
private boolean explicitHibernateEntityAnnotation;
private OptimisticLockType optimisticLockType; private OptimisticLockType optimisticLockType;
private PolymorphismType polymorphismType; private PolymorphismType polymorphismType;
private boolean selectBeforeUpdate; private boolean selectBeforeUpdate;
@ -154,7 +153,6 @@ public class EntityBinder {
public EntityBinder( public EntityBinder(
Entity ejb3Ann, Entity ejb3Ann,
org.hibernate.annotations.Entity hibAnn,
XClass annotatedClass, XClass annotatedClass,
PersistentClass persistentClass, PersistentClass persistentClass,
MetadataBuildingContext context) { MetadataBuildingContext context) {
@ -162,7 +160,7 @@ public class EntityBinder {
this.persistentClass = persistentClass; this.persistentClass = persistentClass;
this.annotatedClass = annotatedClass; this.annotatedClass = annotatedClass;
bindEjb3Annotation( ejb3Ann ); bindEjb3Annotation( ejb3Ann );
bindHibernateAnnotation( hibAnn ); bindHibernateAnnotation();
} }
/** /**
@ -184,47 +182,41 @@ public class EntityBinder {
} }
@SuppressWarnings("SimplifiableConditionalExpression") @SuppressWarnings("SimplifiableConditionalExpression")
private void bindHibernateAnnotation(org.hibernate.annotations.Entity hibAnn) { private void bindHibernateAnnotation() {
{ {
final DynamicInsert dynamicInsertAnn = annotatedClass.getAnnotation( DynamicInsert.class ); final DynamicInsert dynamicInsertAnn = annotatedClass.getAnnotation( DynamicInsert.class );
this.dynamicInsert = dynamicInsertAnn == null this.dynamicInsert = dynamicInsertAnn == null
? ( hibAnn == null ? false : hibAnn.dynamicInsert() ) ? false
: dynamicInsertAnn.value(); : dynamicInsertAnn.value();
} }
{ {
final DynamicUpdate dynamicUpdateAnn = annotatedClass.getAnnotation( DynamicUpdate.class ); final DynamicUpdate dynamicUpdateAnn = annotatedClass.getAnnotation( DynamicUpdate.class );
this.dynamicUpdate = dynamicUpdateAnn == null this.dynamicUpdate = dynamicUpdateAnn == null
? ( hibAnn == null ? false : hibAnn.dynamicUpdate() ) ? false
: dynamicUpdateAnn.value(); : dynamicUpdateAnn.value();
} }
{ {
final SelectBeforeUpdate selectBeforeUpdateAnn = annotatedClass.getAnnotation( SelectBeforeUpdate.class ); final SelectBeforeUpdate selectBeforeUpdateAnn = annotatedClass.getAnnotation( SelectBeforeUpdate.class );
this.selectBeforeUpdate = selectBeforeUpdateAnn == null this.selectBeforeUpdate = selectBeforeUpdateAnn == null
? ( hibAnn == null ? false : hibAnn.selectBeforeUpdate() ) ? false
: selectBeforeUpdateAnn.value(); : selectBeforeUpdateAnn.value();
} }
{ {
final OptimisticLocking optimisticLockingAnn = annotatedClass.getAnnotation( OptimisticLocking.class ); final OptimisticLocking optimisticLockingAnn = annotatedClass.getAnnotation( OptimisticLocking.class );
this.optimisticLockType = optimisticLockingAnn == null this.optimisticLockType = optimisticLockingAnn == null
? ( hibAnn == null ? OptimisticLockType.VERSION : hibAnn.optimisticLock() ) ? OptimisticLockType.VERSION
: optimisticLockingAnn.type(); : optimisticLockingAnn.type();
} }
{ {
final Polymorphism polymorphismAnn = annotatedClass.getAnnotation( Polymorphism.class ); final Polymorphism polymorphismAnn = annotatedClass.getAnnotation( Polymorphism.class );
this.polymorphismType = polymorphismAnn == null this.polymorphismType = polymorphismAnn == null
? ( hibAnn == null ? PolymorphismType.IMPLICIT : hibAnn.polymorphism() ) ? PolymorphismType.IMPLICIT
: polymorphismAnn.type(); : polymorphismAnn.type();
} }
if ( hibAnn != null ) {
// used later in bind for logging
explicitHibernateEntityAnnotation = true;
//persister handled in bind
}
} }
private void bindEjb3Annotation(Entity ejb3Ann) { private void bindEjb3Annotation(Entity ejb3Ann) {
@ -276,13 +268,7 @@ public class EntityBinder {
if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) { if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) {
mutable = false; mutable = false;
} }
else {
org.hibernate.annotations.Entity entityAnn =
annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
if ( entityAnn != null ) {
mutable = entityAnn.mutable();
}
}
rootClass.setMutable( mutable ); rootClass.setMutable( mutable );
rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) ); rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) );
@ -309,9 +295,6 @@ public class EntityBinder {
} }
} }
else { else {
if (explicitHibernateEntityAnnotation) {
LOG.entityAnnotationOnNonRoot(annotatedClass.getName());
}
if (annotatedClass.isAnnotationPresent(Immutable.class)) { if (annotatedClass.isAnnotationPresent(Immutable.class)) {
LOG.immutableAnnotationOnNonRoot(annotatedClass.getName()); LOG.immutableAnnotationOnNonRoot(annotatedClass.getName());
} }
@ -324,22 +307,8 @@ public class EntityBinder {
//set persister if needed //set persister if needed
Persister persisterAnn = annotatedClass.getAnnotation( Persister.class ); Persister persisterAnn = annotatedClass.getAnnotation( Persister.class );
Class persister = null;
if ( persisterAnn != null ) { if ( persisterAnn != null ) {
persister = persisterAnn.impl(); Class persister = persisterAnn.impl();
}
else {
org.hibernate.annotations.Entity entityAnn = annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
if ( entityAnn != null && !BinderHelper.isEmptyAnnotationValue( entityAnn.persister() ) ) {
try {
persister = context.getBootstrapContext().getClassLoaderAccess().classForName( entityAnn.persister() );
}
catch (ClassLoadingException e) {
throw new AnnotationException( "Could not find persister class: " + entityAnn.persister(), e );
}
}
}
if ( persister != null ) {
persistentClass.setEntityPersisterClass( persister ); persistentClass.setEntityPersisterClass( persister );
} }

View File

@ -233,10 +233,6 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Entities updated: %s", id = 80) @Message(value = "Entities updated: %s", id = 80)
void entitiesUpdated(long entityUpdateCount); void entitiesUpdated(long entityUpdateCount);
@LogMessage(level = WARN)
@Message(value = "@org.hibernate.annotations.Entity used on a non root entity: ignored for %s", id = 81)
void entityAnnotationOnNonRoot(String className);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Entity Manager closed by someone else (%s must not be used)", id = 82) @Message(value = "Entity Manager closed by someone else (%s must not be used)", id = 82)
void entityManagerClosedBySomeoneElse(String autoCloseSession); void entityManagerClosedBySomeoneElse(String autoCloseSession);
@ -511,12 +507,6 @@ public interface CoreMessageLogger extends BasicLogger {
int anticipatedNumberOfArguments, int anticipatedNumberOfArguments,
int numberOfArguments); int numberOfArguments);
@LogMessage(level = WARN)
@Message(value = "Class annotated @org.hibernate.annotations.Entity but not javax.persistence.Entity (most likely a user error): %s",
id = 175)
void missingEntityAnnotation(String className);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@Message(value = "Error in named query: %s", id = 177) @Message(value = "Error in named query: %s", id = 177)
void namedQueryError( void namedQueryError(

View File

@ -8,7 +8,7 @@ package org.hibernate.orm.test.annotations.embedded.one2many;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import org.hibernate.annotations.Entity; import javax.persistence.Entity;
/** /**
* TODO : javadoc * TODO : javadoc

View File

@ -12,7 +12,7 @@ import java.util.Set;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import org.hibernate.annotations.Entity; import javax.persistence.Entity;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik

View File

@ -7,6 +7,9 @@
//$Id$ //$Id$
package org.hibernate.orm.test.jpa.cascade; package org.hibernate.orm.test.jpa.cascade;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -30,7 +33,7 @@ import javax.persistence.Table;
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.CHAR) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("X") @DiscriminatorValue("X")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true) @DynamicUpdate @DynamicInsert
public class Conference implements Serializable { public class Conference implements Serializable {
private Long id; private Long id;
private Date date; private Date date;

View File

@ -17,6 +17,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
/** /**
@ -24,8 +26,7 @@ import org.hibernate.annotations.Proxy;
*/ */
@Entity @Entity
@Table(name = "portal_pk_docs_extraction") @Table(name = "portal_pk_docs_extraction")
//@Cache(usage = READ_WRITE) @DynamicUpdate @DynamicInsert
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Proxy @Proxy
public class ExtractionDocument implements Serializable { public class ExtractionDocument implements Serializable {
private Long id; private Long id;

View File

@ -7,6 +7,9 @@
//$Id$ //$Id$
package org.hibernate.orm.test.jpa.cascade; package org.hibernate.orm.test.jpa.cascade;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -29,8 +32,7 @@ import javax.persistence.Transient;
*/ */
@Entity @Entity
@Table(name = "portal_pk_docs_extraction_info") @Table(name = "portal_pk_docs_extraction_info")
//@Cache(usage = READ_WRITE) @DynamicUpdate @DynamicInsert
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
public class ExtractionDocumentInfo implements Serializable { public class ExtractionDocumentInfo implements Serializable {
private Long id; private Long id;
private Date lastModified; private Date lastModified;

View File

@ -13,7 +13,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import org.hibernate.annotations.Entity; import javax.persistence.Entity;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik

View File

@ -16,14 +16,19 @@ import javax.persistence.Id;
import javax.persistence.Lob; import javax.persistence.Lob;
import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Filter; import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.Index; import org.hibernate.annotations.Index;
import org.hibernate.annotations.OptimisticLock; import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;
import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType; import org.hibernate.annotations.PolymorphismType;
import org.hibernate.annotations.SelectBeforeUpdate;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@ -34,11 +39,10 @@ import org.hibernate.annotations.Where;
*/ */
@Entity @Entity
@BatchSize(size = 5) @BatchSize(size = 5)
@org.hibernate.annotations.Entity( @SelectBeforeUpdate
selectBeforeUpdate = true, @DynamicInsert @DynamicUpdate
dynamicInsert = true, dynamicUpdate = true, @OptimisticLocking(type = OptimisticLockType.ALL)
optimisticLock = OptimisticLockType.ALL, @Polymorphism(type = PolymorphismType.EXPLICIT)
polymorphism = PolymorphismType.EXPLICIT)
@Where(clause = "1=1") @Where(clause = "1=1")
@FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = "integer")}) @FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = "integer")})
@Filter(name = "betweenLength") @Filter(name = "betweenLength")

View File

@ -22,7 +22,7 @@ import org.hibernate.annotations.Type;
/** /**
* Mapping following lines of {@link Forest}, but using the replacements for the now deprecated * Mapping following lines of {@link Forest}, but using the replacements for the now deprecated
* {@link org.hibernate.annotations.Entity} annotation. * {@link javax.persistence.Entity} annotation.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -12,13 +12,14 @@ import javax.persistence.Id;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Entity @Entity
@org.hibernate.annotations.Entity(mutable = false) @Immutable
public class ZipCode { public class ZipCode {
@Id @Id
public String code; public String code;

View File

@ -5,6 +5,8 @@
* 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.test.annotations.persister; package org.hibernate.test.annotations.persister;
import org.hibernate.annotations.Persister;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
@ -15,7 +17,7 @@ import javax.persistence.ManyToOne;
* @author Shawn Clowater * @author Shawn Clowater
*/ */
@Entity @Entity
@org.hibernate.annotations.Entity( persister = "org.hibernate.persister.entity.SingleTableEntityPersister" ) @Persister( impl = org.hibernate.persister.entity.SingleTableEntityPersister.class )
public class Card implements Serializable { public class Card implements Serializable {
@Id @Id
public Integer id; public Integer id;

View File

@ -18,7 +18,6 @@ import org.hibernate.annotations.Persister;
* @author Shawn Clowater * @author Shawn Clowater
*/ */
@Entity @Entity
@org.hibernate.annotations.Entity( persister = "org.hibernate.persister.entity.SingleTableEntityPersister" )
@Persister( impl = org.hibernate.test.annotations.persister.EntityPersister.class ) @Persister( impl = org.hibernate.test.annotations.persister.EntityPersister.class )
public class Deck implements Serializable { public class Deck implements Serializable {
@Id @Id

View File

@ -15,6 +15,7 @@ import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType; import org.hibernate.annotations.PolymorphismType;
/** /**
@ -22,7 +23,7 @@ import org.hibernate.annotations.PolymorphismType;
*/ */
@Entity @Entity
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT) @Polymorphism(type = PolymorphismType.EXPLICIT)
public class Car extends Automobile { public class Car extends Automobile {
@Id @Id

View File

@ -10,6 +10,7 @@ package org.hibernate.test.annotations.polymorphism;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType; import org.hibernate.annotations.PolymorphismType;
/** /**
@ -17,6 +18,6 @@ import org.hibernate.annotations.PolymorphismType;
*/ */
@Entity @Entity
@Table(name = "sport_car") @Table(name = "sport_car")
@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT) //raise a warn @Polymorphism(type = PolymorphismType.EXPLICIT) //raise a warn
public class SportCar extends Car { public class SportCar extends Car {
} }