Sunday, February 24, 2019

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 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

No comments:

Post a Comment

Popular Posts