Consideration on Java Persistence Framework 2017 (7) EclipseLink

Previous post

-Discussion on Java Persistence Framework for 2017 (1) -Consideration of 2017 Java Persistence Framework (2) Doma2 -Guessing about the 2017 Java Persistence Framework (3) Reladomo -Discussion on Java Persistence Framework for 2017 (4) jOOQ -Considerations on the 2017 Java Persistence Framework (5) Iciql -Discussion on Java Persistence Framework for 2017 (6) Ebean

Preface

Since I am writing using the gap time, I would appreciate it if you could point out any parts with poor accuracy. First, exclude those that are EOL. We will consider paid functions, but we will not actually use them, due to the problem of pockets. The DB used is fixed to Postgre for a stupid reason such as "Well, maybe Postgre can be used even if it is not specified."

environment

Table structure

employeeテーブルからpostテーブルにID紐づけ

Correspondence range

ORM Transaction Data Model DSL
×

○: Correspondence ×: Not supported

Impressions

--There is no automatic generation of entities. --The EntityManager specification seems to be a roundabout when used in a containerless environment. --I forgot until I used persistence.xml --JPA 2.0 uses annotation processing to generate metamodels, type safe, column name change resistance, etc. are powered up ―― …… Isn't it dull compared to metamodels and other ORM libraries? --EclipseLink 2.7.0 javax.persistence error due to incorrect signature, why, after all, avoid the mystery of inserting javax.persistence 2.1.1

sample

Single table search

Search all

Main.java


CriteriaQuery<Employee> query = em.getCriteriaBuilder().createQuery(Employee.class);
em.createQuery(query).getResultStream().forEach(e -> {
    System.out.format("%1s: %2s, %3s, %4s\n", e.id, e.first_name, e.middle_name, e.last_name);
});

Primary key search

Main.java


CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Employee> query = builder.createQuery(Employee.class);
Root<Employee> root = query.from(Employee.class);
em.createQuery(query.select(root).where(builder.equal(root.get(Employee_.id), 1L)))
        .getResultStream()
        .forEach(e -> {
    System.out.format("%1s: %2s, %3s, %4s\n", e.id, e.first_name, e.middle_name, e.last_name);
});

Table join

Main.java


em.createQuery(query.select(root).where(builder.equal(root.get(Employee_.id), 1L)))
        .getResultStream()
        .forEach(e -> {
    System.out.format("%1s: %2s, %3s, %4s\n", e.id, e.first_name, e.middle_name, e.last_name);
    e.posts.stream().forEach(p -> {
        System.out.format("\t%1s: %2s, %3s\n", p.id, p.employee_id, p.name);
    });
});

Employee.java


@Entity
@Table(name="employee")
public class Employee {
    @Id
    public long id;
    public String first_name;
    public String middle_name;
    public String last_name;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "employee_id", table = "post")
    public List<Post> posts;
}

Post.java


@Entity
@Table(name="post")
public class Post {
    @Id
    public long id;
    public long employee_id;
    public String name;
}

The point

--JPA reference implementation, so JPA

Addictive points

--When you build using EclipseLink 2.7.0 normally, you get angry that "javax.persistence signature is different". -Bug 525457 Seriously Kayo Jotaro

After post

Is not yet.

Reference article

-JPA Mapping Catalog -JavaEE Usage Memo (JPA Part 4-Criteria API)

Recommended Posts

Consideration on Java Persistence Framework 2017 (7) EclipseLink
Consideration on Java Persistence Framework 2017 (Summary) -1
Consideration on Java Persistence Framework 2017 (6) Ebean
Consideration on Java Persistence Framework 2017 (5) Iciql
Consideration on the 2017 Java Persistence Framework (1)
Consideration on Java Persistence Framework 2017 (8) Hibernate5
Consideration on Java Persistence Framework 2017 (2) Doma2
java framework
Guess about the 2017 Java Persistence Framework (3) Reladomo
Java framework comparison
[Java] Collection framework
Play Framework2.5 (Java) Tips
Let's touch on Java
[Development] Java framework comparison
Learning Java framework # 1 (Mac version)
Java version control on macOS
Install OpenJDK7 (JAVA) on ubuntu 14.04
Downgrade Java on openSUSE Linux
Reflection on Java string manipulation
On passing Java Gold SE 8
Oracle Java 8 on Docker Ubuntu
Java Collections Framework Review Notes
Install Java on WSL Ubuntu 18.04
Run java applet on ubuntu
Put Oracle Java 8 on CircleCI 2
Java version change on CentOS
Install java 1.8.0 on Amazon linux2