O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Let's start with adding the javax.persistence package dependency to the Maven configuration file pom.xml:   
<dependency>    <groupId>javax.persistence</groupId>    <artifactId>javax.persistence-api</artifactId>    <version>2.2</version></dependency>

We don't need any of the JPA implementations yet. This way, we can make sure that our code does not use any framework-specific code and uses only JPA interfaces. 

  1. Create the class Person1:
public class Person1 {    private int age;    private String name;    public Person1(int age, String name){        this.age = age;        this.name = name;    }    @Override    public String toString() {        return "Person1{id=" + id + ", age=" + age +                          ", name='" + name + "'}";    }}

We don't add getters, setters, or any other methods; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required