Friday, 14 June 2013

Hibernate Data types

Hibernate Data Types :
Hibernate data type plays an important roll as it acts like a bridge between java types and DB data types.
It is necessary to choose correct data type during table creation. Hibernate data types are used when we write 
hibernate mapping files(*.hbm.xml) . This is also known as mapping types.
Here we are categorizing the mapping types in  Hibernate -
1. Primitive Types :
Java TypeHibernate TypeSQL Type
int/java.lang.Integerinteger INTEGER
long/java.lang.LonglongBIGINT
short/java.lang.ShortshortSMALLINT
float/java.lang.FloatfloatFloat
double/java.lang.DoubledoubleDOUBLE
java.math.BigDecimalbig_decimalNUMERIC
java.lang.StringcharacterCHAR(1)
java.lang.StringstringVARCHAR
byte/java.lang.BytebyteTINYINT
boolean/java.lang.BooleanbooleanBIT
boolean/java.lang.Booleanyes_noCHAR(1)('Y' or 'N')
boolean/java.lang.Booleantrue/falseCHAR(1)('T' or 'F')
2.Date and Time Type :
Java TypeHibernate TypeSQL Type
java.util.Date/java.sql.DatedateDATE
java.util.Date/java.sql.TimetimeTIME
java.util.Date/java.sql.TimestamptimestampTIMESTAMP
java.util.CalendercalenderTIMESTAMP
java.util.Calendercalender_dateDATE
3.Binary and Large Object Type :
Java TypeHibernate TypeSQL Type
byte[]binaryVARBINARY/BLOB
java.lang.StringtextCLOB
any java class that implements java.io.SerializableserializableVARBINARY/BLOB
java.sql.ClobclobCLOB
java.sql.BlobblobBLOB
4.Other JDK-related Type :
Java TypeHibernate TypeSQL Type
java.lang.ClassclassVARCHAR
java.util.LocalelocaleVARCHAR
java.util.TimeZonetimezoneVARCHAR
java.util.CurrencycurrencyVARCHAR

No comments:

Post a Comment