0

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?

9
  • Are you using Java lower than 5? Commented Feb 14, 2019 at 14:02
  • no, using java 9 Commented Feb 14, 2019 at 14:10
  • what is JAVA_HOME pointing to? Commented Feb 14, 2019 at 14:34
  • using eclipse, so JRE is set up in build bath, using jdk openjdk version "10.0.2" 2018-07-17 Commented Feb 14, 2019 at 14:40
  • it doesn't matter, can you answer my question? Commented Feb 14, 2019 at 14:42

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I have that node in my pom.xml already. tried removing the @Generated annotations, and then ran maven with package and compile as goals

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.