Java-to-SQL data conversion turns an entity’s basic property values into database values. A JPA provider supplies standard mappings; Hibernate and Spring Data JPA with Hibernate also offer additional adapters. For example, an int maps to SQL INTEGER, a BigDecimal to NUMERIC, and a LocalDate to DATE. section 6.3.1
Table 6.1 Java primitive types that map to SQL standard types (view table figure)
Compare Java primitives and numeric classes with their standard SQL types. section 6.3.1
The SQL type named by a mapping need not be the type named by a particular DBMS. JDBC partly abstracts vendor differences during INSERT and UPDATE; when Hibernate generates a schema, its configured SQL dialect translates standard types into vendor-specific column types. For an existing schema, check the dialect’s mapping. A BigDecimal defaults to NUMERIC(19, 2); use @Column precision and scale to change its generated definition. section 6.3.1
Choose a mapping that fits both the Java value and its stored representation:
- Strings commonly use VARCHAR; Hibernate also offers character-based adapters, including boolean values stored as 'Y'/'N' or 'T'/'F'. section 6.3.1
- Date and time values have distinct mappings: LocalDate uses DATE, LocalTime uses TIME, and Instant uses TIMESTAMP. section 6.3.1
- Binary and large values have alternatives: byte[] maps to VARBINARY, while @Lob on byte[] or String expresses a large-object mapping. Blob and Clob properties can represent large objects directly. section 6.3.1
Select a boolean representation
If a boolean property must be stored as a single 'Y' or 'N' character, annotate it with Hibernate’s @Type(type = "yes_no") rather than relying on the built-in BOOLEAN mapping. This choice is Hibernate-specific. section 6.3.1
When built-in mappings do not fit a domain value, implement a custom converter through standard JPA extension interfaces or a lower-level adapter through Hibernate’s UserType API. Prefer a built-in mapping when its representation fits; use a custom conversion when the property needs one the built-in adapters do not provide. section 6.4




















