Hibernate Mapping Types

Advertisements


When you prepare a Hibernate mapping document, we have seen that you map 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 typeJava typeANSI SQL Type
integerint or java.lang.IntegerINTEGER
longlong or java.lang.LongBIGINT
shortshort or java.lang.ShortSMALLINT
floatfloat or java.lang.FloatFLOAT
doubledouble or java.lang.DoubleDOUBLE
big_decimaljava.math.BigDecimalNUMERIC
characterjava.lang.StringCHAR(1)
stringjava.lang.StringVARCHAR
bytebyte or java.lang.ByteTINYINT
booleanboolean or java.lang.BooleanBIT
yes/noboolean or java.lang.BooleanCHAR(1) ('Y' or 'N')
true/falseboolean or java.lang.BooleanCHAR(1) ('T' or 'F')

Date and time types:

Mapping typeJava typeANSI SQL Type
datejava.util.Date or java.sql.DateDATE
timejava.util.Date or java.sql.TimeTIME
timestampjava.util.Date or java.sql.TimestampTIMESTAMP
calendarjava.util.CalendarTIMESTAMP
calendar_datejava.util.CalendarDATE

Binary and large object types:

Mapping typeJava typeANSI SQL Type
binarybyte[]VARBINARY (or BLOB)
textjava.lang.StringCLOB
serializableany Java class that implements java.io.SerializableVARBINARY (or BLOB)
clobjava.sql.ClobCLOB
blobjava.sql.BlobBLOB

JDK-related types:

Mapping typeJava typeANSI SQL Type
classjava.lang.ClassVARCHAR
localejava.util.LocaleVARCHAR
timezonejava.util.TimeZoneVARCHAR
currencyjava.util.CurrencyVARCHAR


Advertisements
Advertisements