Schemint

paste PostgreSQL or JSON, get your schema reviewed like a senior would

From CREATE TABLE to JPA Entity: the type mapping

Transcribing DDL into a JPA Entity is mechanical work full of small decisions: which Java type for NUMERIC? IDENTITY or SEQUENCE? Does nullable go in the annotation or do you trust the database? Here's the mapping Schemint uses and the reasoning behind each choice.

PostgreSQL to Java type table

PostgreSQLJavaNote
BIGSERIAL / BIGINTLonggenerated id: @GeneratedValue(strategy = IDENTITY)
SERIAL / INTEGERInteger
VARCHAR(n) / TEXTString@Column(length = n) when there's a limit
NUMERIC(p,s)BigDecimalnever double for money
BOOLEANBoolean
TIMESTAMPLocalDateTime
TIMESTAMPTZInstanta real instant, normalized to UTC
DATELocalDate
UUIDUUID
JSONBStringor @JdbcTypeCode(SqlTypes.JSON) with your own type

Wrapper types (Long, not long): a nullable column has to be able to represent absence, and a primitive with a magic 0 value is a bug waiting to happen.

The generated skeleton

@Entity
@Table(name = "customers")
public class CustomerEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 120)
    private String name;

    @Column(nullable = false, unique = true, length = 180)
    private String email;
}

Paste your CREATE TABLE into Schemint and get back the Entity, request/response records, repository, Flyway migration, ER diagram and the schema warnings. It runs in the browser and nothing is stored.