Open In App

Hibernate – Types of Mapping

Last Updated : 15 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
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 Type Java Type ANSI SQL Type
integer int or java.lang.Integer INTEGER
character java.lang.String CHAR(1)
float float or java.lang.Float FLOAT
string java.lang.String VARCHAR
double double or java.lang.Double DOUBLE
boolean boolean or java.lang.Boolean BIT
short short or java.lang.Short SMALLINT
long long or java.lang.Long BIGINT
byte byte or java.lang.Byte TINYINT
big_decimal java.math.BigDecimal NUMERIC

B. Date and Time

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

Mapping type Java type ANSI SQL Type
date java.util.Date or java.sql.Date DATE
time java.util.Date or java.sql.Time TIME
calendar java.util.Calendar TIMESTAMP
timestamp java.util.Date or java.sql.Timestamp TIMESTAMP
calendar_date java.util.Calendar DATE

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 type Java type ANSI SQL Type
clob java.sql.Clob CLOB
blob java.sql.Blob BLOB
binary byte[] VARBINARY (or BLOB)
text java.lang.String CLOB
serializable any Java class that implements java.io.Serializable VARBINARY (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 type Java type ANSI SQL Type
class java.lang.Class  VARCHAR
locale java.util.Locale VARCHAR
currency java.util.Currency VARCHAR
timezone java.util.Currency VARCHAR

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads