Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java add javax.persistence in IntelliJ

I am trying to create a basic Java Spring program. Where do I get javax.persistence? It cannot resolve persistence, and cannot Find JAR on Web after attempting. Currently using IntelliJ .

https://spring.io/guides/tutorials/rest/

package payroll;

import java.util.Objects;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
class Employee {

  private @Id @GeneratedValue Long id;
  private String name;
  private String role;

enter image description here

like image 967
mattsmith5 Avatar asked Oct 19 '25 10:10

mattsmith5


1 Answers

That dependency comes from the spring-boot-starter-data-jpa.

Please review the suggested dependencies in the tutorial (jpa, web, h2).

If you're using Gradle you should have:

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
  implementation 'org.springframework.boot:spring-boot-starter-web'
  runtimeOnly 'com.h2database:h2'
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Or Maven:

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
like image 160
JuanMoreno Avatar answered Oct 20 '25 23:10

JuanMoreno