jpa Basic mapping A very simple entity

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

@Entity
class Note {
    @Id
    Integer id;
 
    @Basic
    String note;

    @Basic
    int count;
}

Getters, setters etc. are ommitted for brevity, but they are not needed for JPA anyway.

This Java class would map to the following table (depending on your database, here given in one possible Postgres mapping):

CREATE TABLE Note (
  id integer NOT NULL,
  note text,
  count integer NOT NULL
)

JPA providers may be used to generate the DDL, and will likely produce DDL different from the one shown here, but as long as the types are compatible, this will not cause problems at runtime. It is best not to rely on auto-generation of DDL.



Got any jpa Question?