5.2.2. Basic value types
The built-in basic mapping types can be roughly categorized into the following:
integer, long, short, float, double, character, byte, boolean, yes_no, true_false
- Type mappings from Java primitives or wrapper classes to appropriate (vendor-specific) SQL column types.
boolean, yes_no
andtrue_false
are all alternative encodings for a Javaboolean
orjava.lang.Boolean
. string
- A type mapping from
java.lang.String
toVARCHAR
(or OracleVARCHAR2
). date, time, timestamp
- Type mappings from
java.util.Date
and its subclasses to SQL typesDATE
,TIME
andTIMESTAMP
(or equivalent). calendar, calendar_date
- Type mappings from
java.util.Calendar
to SQL typesTIMESTAMP
andDATE
(or equivalent). big_decimal, big_integer
- Type mappings from
java.math.BigDecimal
andjava.math.BigInteger
toNUMERIC
(or OracleNUMBER
). locale, timezone, currency
- Type mappings from
java.util.Locale
,java.util.TimeZone
andjava.util.Currency
toVARCHAR
(or OracleVARCHAR2
). Instances ofLocale
andCurrency
are mapped to their ISO codes. Instances ofTimeZone
are mapped to theirID
. class
- A type mapping from
java.lang.Class
toVARCHAR
(or OracleVARCHAR2
). AClass
is mapped to its fully qualified name. binary
- Maps byte arrays to an appropriate SQL binary type.
text
- Maps long Java strings to a SQL
CLOB
orTEXT
type. serializable
- Maps serializable Java types to an appropriate SQL binary type. You can also indicate the Hibernate type
serializable
with the name of a serializable Java class or interface that does not default to a basic type. clob, blob
- Type mappings for the JDBC classes
java.sql.Clob
andjava.sql.Blob
. These types can be inconvenient for some applications, since the blob or clob object cannot be reused outside of a transaction. Driver support is patchy and inconsistent. -
imm_date, imm_time, imm_timestamp, imm_calendar, imm_calendar_date, imm_serializable, imm_binary
- Type mappings for what are considered mutable Java types. This is where Hibernate makes certain optimizations appropriate only for immutable Java types, and the application treats the object as immutable. For example, you should not call
Date.setTime()
for an instance mapped asimm_timestamp
. To change the value of the property, and have that change made persistent, the application must assign a new, nonidentical, object to the property.
Unique identifiers of entities and collections can be of any basic type except
binary
, blob
and clob
. Composite identifiers are also allowed. See below for more information.
The basic value types have corresponding
Type
constants defined on org.hibernate.Hibernate
. For example, Hibernate.STRING
represents the string
type.