diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/processing/Suppress.java b/hibernate-core/src/main/java/org/hibernate/annotations/processing/Suppress.java new file mode 100644 index 0000000000..cc0bcf3170 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/annotations/processing/Suppress.java @@ -0,0 +1,29 @@ +/* + * 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.processing; + +import org.hibernate.Incubating; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +/** + * Indicates that a package or top-level type should be ignored + * by the Hibernate annotation processor. + * + * @author Gavin King + * @since 6.5 + */ +@Target({PACKAGE, TYPE}) +@Retention(CLASS) +@Incubating +public @interface Suppress { +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/ShowDescription.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/ShowDescription.java index 3c3f8de59f..4bfac9848d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/ShowDescription.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/ShowDescription.java @@ -10,10 +10,12 @@ package org.hibernate.orm.test.annotations.onetoone; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; +import org.hibernate.annotations.processing.Suppress; /** * @author Emmanuel Bernard */ +@Suppress @Entity public class ShowDescription { @Id diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java index b7b2fdfbce..4199b5afb5 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java @@ -279,7 +279,11 @@ public class HibernateProcessor extends AbstractProcessor { for ( Element element : roundEnvironment.getRootElements() ) { try { - if ( isEntityOrEmbeddable( element ) ) { + if ( hasAnnotation( element, SUPPRESS) + || hasAnnotation( context.getElementUtils().getPackageOf(element), SUPPRESS ) ) { + // skip it completely + } + else if ( isEntityOrEmbeddable( element ) ) { context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" ); handleRootElementAnnotationMirrors( element ); } diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java index 5d8c45ccc2..db9fe54963 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java @@ -61,6 +61,7 @@ public final class Constants { public static final String SQL = "org.hibernate.annotations.processing.SQL"; public static final String FIND = "org.hibernate.annotations.processing.Find"; public static final String PATTERN = "org.hibernate.annotations.processing.Pattern"; + public static final String SUPPRESS = "org.hibernate.annotations.processing.Suppress"; public static final String JD_REPOSITORY = "jakarta.data.repository.Repository"; public static final String JD_QUERY = "jakarta.data.repository.Query";