April 2018
Intermediate to advanced
202 pages
4h 48m
English
JPA is an ORM framework. It maps SQL tables to Java objects. We already have the SQL table, messages, but what about the Java counterpart? We need to define a Message class. If you had a look at the code for the JDBC section, you probably saw the SQL code to create the messages table. If not, here it is:
CREATE TABLE messages(id BIGINT auto_increment, content VARCHAR(255))
We want that table to be represented on the Java side as:
public class Message { private Long id; private String content; ... getters and setters ...}
This class is going to be what JPA calls an Entity class, a POJO class (Plain Old Java Object) that is annotated to match an SQL table. You can use annotations to tell JPA how to map the objects ...
Read now
Unlock full access