badperson
badperson

Reputation: 1624

Hibernate JPA @Generated annotation compile error

I'm starting a maven/hibernate project using eclipse, and I'm having an issue with my metamodel classes.

I'm getting a red x for lines dealing with the @Generated annotation:

import javax.annotation.Generated;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")

I've reviewed the documentation and it describes an option addGeneratedAnnotation:

If set to true the processor will add the @Generated to the generated Java source file. Adding this annotation using JDK 5 will cause a compilation error. In this case set the flag to false. The default for this option is true

where do I set that option in eclipse? In the run config? I tried that, doing just a maven compile, but that did not fix it. Which maven goal will generated new metamodel classes.

I'm pretty sure I have the build path and factory path set up right. I am using java 9.

I have my pom.xml file to include the following

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>5.3.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.3.1.Final</version>
</dependency>

update

I tried running package and compile in maven, but was getting the version error 52.0/53.0.

has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I was able to resolve by setting compiler level and project facet java level to 1.8.

Is there a way to get this set up with later versions?

Upvotes: 0

Views: 1576

Answers (2)

bessam Sahli
bessam Sahli

Reputation: 105

you need to import the hibernate library if you are using Maven yse this

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>{hibernate.version}</version>
    <scope>provided</scope>
</dependency>

for gradle

org.hibernate:hibernate-core:5.4.1.Final

or add the hibernate library to your project manually

Upvotes: 1

Filipe Oliveira
Filipe Oliveira

Reputation: 1

Try add this maven dependency in your pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>{hibernate.version}</version>
    <scope>provided</scope>
</dependency>

After that remove the @Generated of your classes and execute:

 mvn package

The Modelgen will generate your metamodel in target/...

The local where the metamodel has generated should be in your classpath.

Upvotes: 0

Related Questions