0

I have the following Java code which errors on when I run

mvn clean install

In my source code, I have the following imports

import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; 

and in my pom.xml I had the following

<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>   

and I was getting the following error

error: package javax.persistence does not exist

I thought that maybe there was an error with the entry in the pom, so I tried to change the pom to the following

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>javax.persistence-api</artifactId>
    <version>2.2</version>
</dependency>

and I still get the following error. I am not sure what's causing the issue and how to fix it.

p0tta
  • 1,461
  • 6
  • 28
  • 49
  • Are you sure it is put under build/dependencies instead of dependencyManagement ? Or, could it be declared as `runtime` scope? Check by doing `mvn dependency:tree` – Adrian Shum Nov 04 '20 at 03:24
  • All of my other dependencies are in dependencyManagement but when I moved it out of there into build/dependencies it worked. Not sure why they were in dependencyManagement in the first place? What's the use of adding them there? – p0tta Nov 04 '20 at 04:09
  • 1
    in short, dependencyManagement is NOT dependency. you can treat it as some pre-defined settings for a dependency, WHEN you are adding such dependency. https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven – Adrian Shum Nov 04 '20 at 04:13

1 Answers1

1

Try to replace it with

 <dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>persistence-api</artifactId>  
  <version>1.0</version>
 </dependency>
Lyes
  • 400
  • 5
  • 19