liveBook · Manning

Hibernate type system

As explained in Java Persistence with Spring Data and Hibernate epub

The Hibernate type system is the framework subsystem that selects and performs mappings between Java property types and SQL or vendor-specific database types.

The Hibernate type system maps Java property types to SQL types. The configured SQL dialect then influences the database-specific column type used during schema generation. For example, a BigDecimal property defaults to NUMERIC(19, 2); @Column(precision = ..., scale = ...) changes those settings. section 6.3.1

String columns also depend on mapping settings and dialect. With no specified length, a String maps to VARCHAR(255). Setting @Column(length = ...) or a Bean Validation @Length can change the selected SQL type; a MySQL dialect may select VARCHAR, MEDIUMTEXT, or LONGTEXT according to length. section 6.3.1

Choose a legacy boolean representation

Annotate a boolean property with @Type(type = "yes_no") to use the built-in mapping to CHAR(1) values 'Y' and 'N', rather than the standard BOOLEAN mapping. section 6.3.1

Table 6.2 Adapters for character and string values (view table figure)

Name

Java type

ANSI SQL type

string

java.lang.String

VARCHAR

character

char[], Character[], java.lang.String

CHAR

yes_no

boolean, java.lang.Boolean

CHAR(1), 'Y' or 'N'

true_false

boolean, java.lang.Boolean

CHAR(1), 'T' or 'F'

class

java.lang.Class

VARCHAR

locale

java.util.Locale

VARCHAR

timezone

java.util.TimeZone

VARCHAR

currency

java.util.Currency

VARCHAR

Compare built-in mappings for String, character arrays, booleans, and other values represented as SQL character types. section 6.3.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains built-in mappings and shows how length, precision, annotations, and dialect affect type selection; does not detail implementation internals.
Examples
Uses BigDecimal precision, MySQL string lengths, and a yes_no boolean property to illustrate mapping choices.
What you can do after
Operate/configure it with @Column, @Length, or @Type to influence selected SQL types and stored values.
How it connects
Connects SQL dialects, schema generation, Bean Validation, and JPA annotations to property-type mapping.

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.