diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java index d13e0de30f..1d49d5a8d9 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java @@ -198,7 +198,7 @@ public final class ClassWriter { private static String writeGeneratedAnnotation(MetaEntity entity, Context context) { StringBuilder generatedAnnotation = new StringBuilder(); generatedAnnotation.append( "@" ) - .append( entity.importType( "javax.annotation.Generated" ) ) + .append( entity.importType( context.getGeneratedAnnotation().getQualifiedName().toString() ) ) .append( "(value = \"" ) .append( JPAMetaModelEntityProcessor.class.getName() ); if ( context.addGeneratedDate() ) { diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/Context.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/Context.java index a7ca2fe465..978bd35c3e 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/Context.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/Context.java @@ -50,6 +50,7 @@ public final class Context { private final boolean lazyXmlParsing; private final String persistenceXmlLocation; private final List ormXmlFiles; + private final TypeElement generatedAnnotation; /** * Whether all mapping files are xml-mapping-metadata-complete. In this case no annotation processing will take @@ -94,6 +95,16 @@ public final class Context { lazyXmlParsing = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.LAZY_XML_PARSING ) ); logDebug = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.DEBUG_OPTION ) ); + + TypeElement java8AndBelowGeneratedAnnotation = + pe.getElementUtils().getTypeElement( "javax.annotation.Generated" ); + if ( java8AndBelowGeneratedAnnotation != null ) { + generatedAnnotation = java8AndBelowGeneratedAnnotation; + } + else { + // Using the new name for this annotation in Java 9 and above + generatedAnnotation = pe.getElementUtils().getTypeElement( "javax.annotation.processing.Generated" ); + } } public ProcessingEnvironment getProcessingEnvironment() { @@ -104,6 +115,10 @@ public final class Context { return addGeneratedAnnotation; } + public TypeElement getGeneratedAnnotation() { + return generatedAnnotation; + } + public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) { this.addGeneratedAnnotation = addGeneratedAnnotation; }