Andrei Pall

Linux Software Engineering

Hibernate - Mapping Types

When you prepare a Hibernate mapping document, you find that you map the Java data types into RDBMS data types. The types declared and used in the mapping files are not Java data types; they are not SQL database types either. These types are called Hibernate mapping types, which can translate from Java to SQL data types and vice versa.

This chapter lists down all the basic, date and time, large object, and various other builtin mapping types.

Primitive Types

Mapping type Java type ANSI SQL Type
integer int or java.lang.Integer INTEGER
long long or java.lang.Long BIGINT
short short or java.lang.Short SMALLINT
float float or java.lang.Float FLOAT
double double or java.lang.Double DOUBLE
big_decimal java.math.BigDecimal NUMERIC
character java.lang.String CHAR(1)
string java.lang.String VARCHAR
byte byte or java.lang.Byte TINYINT
boolean boolean or java.lang.Boolean BIT
yes/no boolean or java.lang.Boolean CHAR(1) ('Y' or 'N')
true/false boolean or java.lang.Boolean CHAR(1) ('T' or 'F')

Date and Time Types

Mapping type Java type ANSI SQL Type
date java.util.Date or java.sql.Date DATE
time java.util.Date or java.sql.Time TIME
timestamp java.util.Date or java.sql.Timestamp TIMESTAMP
calendar java.util.Calendar TIMESTAMP
calendar_date java.util.Calendar DATE

Binary and Large Object Types

Mapping type Java type ANSI SQL Type
binary byte[] VARBINARY (or BLOB)
text java.lang.String CLOB
serializable any Java class that implements java.io.Serializable VARBINARY (or BLOB)
clob java.sql.Clob CLOB
blob java.sql.Blob BLOB

JDK-related Types

Mapping type Java type ANSI SQL Type
class java.lang.Class VARCHAR
locale java.util.Locale VARCHAR
timezone java.util.TimeZone VARCHAR
currency java.util.Currency VARCHAR

Hibernate Types

Hibernate type (org.hibernate.type) JDBC type Java type
StringType VARCHAR String
MaterializedClob CLOB String
TextType LONGVARCHAR String
CharacterType CHAR char or Character
BooleanType BIT boolean or Boolean
NumericBooleanType INTEGER (e.g. 0 = false and 1 = true) boolean or Boolean
YesNoType CHAR (e.g. ‘N’ or ‘n’ = false and ‘Y’ or ‘y’ = true) boolean or Boolean
TrueFalseType CHAR (e.g. ‘F’ or ‘f’ = false and ‘T’ or ‘t’ = true) boolean or Boolean
ByteType TINYINT byte or Byte
ShortType SMALLINT short or Short
IntegerType INTEGER int or Integer
LongType BIGINT long or Long
FloatType FLOAT float or Float
DoubleType DOUBLE double or Double
BigIntegerType NUMERIC BigInteger
BigDecimalType NUMERIC BigDecimal
TimestampType TIMESTAMP java.sql.Timestamp or java.util.Date
TimeType TIME java.sql.Time
DateType DATE java.sql.Date
CalendarType TIMESTAMP java.util.Calendar or java.util.GregorianCalendar
CalendarType DATE java.util.Calendar or java.util.GregorianCalendar
CurrencyType VARCHAR java.util.Currency
LocaleType VARCHAR java.util.Locale
TimeZoneType VARCHAR java.util.TimeZone
UrlType VARCHAR java.net.URL
ClassType VARCHAR java.lang.Class
BlobType BLOB java.sql.Blob
ClobType CLOB java.sql.Clob
BinaryType VARBINARY byte[] or Byte[]
BinaryType BLOB byte[] or Byte[]
BinaryType LONGVARBINARY byte[] or Byte[]
BinaryType LONGVARBINARY byte[] or Byte[]
CharArrayType VARCHAR char[] or Character[]
UUIDBinaryType BINARY java.util.UUID
UUIDBinaryType CHAR or VARCHAR java.util.UUID
UUIDBinaryType PostgreSQL UUID java.util.UUID
SerializableType VARBINARY Serializable