Open In App
Related Articles

Hibernate – Types of Mapping

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Hibernate is a Java framework that simplifies the development of Java applications to interact with the database. It is an open-source, lightweight, ORM (Object Relational Mapping) tool. Hibernate implements the specifications of JPA (Java Persistence API) for data persistence.

There are different relations that we maintain to establish a link between different database tables in relational database models. These relations are one to one, one to many, and many to many. A similar concept is being installed in hibernate. Here the hibernate works to link the JAVA language to the database table along with this link we can establish relations/mappings. 

The main basic types of mapping are: 

  1. Primitive Types
  2. Date and Time Types
  3. Binary and Large Object Types
  4. JDK-related Types

So, let us discuss each of the above 4 listed mapping types in detail as follows:

A. Primitive Types 

These types of mapping have data types defined as “integer”, “character”, “float”, “string”, “double”, “Boolean”, “short”, “long” etc. These are present in hibernate framework to map java data type to RDBMS data type.        

Mapping TypeJava TypeANSI SQL Type
integerint or java.lang.IntegerINTEGER
characterjava.lang.StringCHAR(1)
floatfloat or java.lang.FloatFLOAT
stringjava.lang.StringVARCHAR
doubledouble or java.lang.DoubleDOUBLE
booleanboolean or java.lang.BooleanBIT
shortshort or java.lang.ShortSMALLINT
longlong or java.lang.LongBIGINT
bytebyte or java.lang.ByteTINYINT
big_decimaljava.math.BigDecimalNUMERIC

B. Date and Time

These are “date”, “time”, “calendar”, “timestamp” etc. Like primitive we have these date and time datatype mappings.

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

C. Binary and large objects 

These types are “clob”, “blob”, “binary”, “text” etc. Clob and blob data types are present to maintain the data type mapping of large objects like images and videos.

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

D. JDK linked

Some of the mappings for objects which lie beyond the reach of the previous type of mappings are included in this category. These are “class”, “locale”, “currency”, “timezone”.

Mapping typeJava typeANSI SQL Type
classjava.lang.Class VARCHAR
localejava.util.LocaleVARCHAR
currencyjava.util.CurrencyVARCHAR
timezonejava.util.CurrencyVARCHAR

Last Updated : 15 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads