Hibernate Tutorial-mapping types

Source: Internet
Author: User
Tags time and date

There are two types of hibernate mappings: The built-in mapping type and the custom mapping type. The built-in mapping type is responsible for mapping some common Java types to the appropriate SQL type, and hibernate also allows users to implement Usertype or Compositeusertype interfaces to flexibly customize custom mapping types. A custom type can map a user-defined Java type to a corresponding field in a database table.

First, Hibernate's built-in mapping type

1. Types of hibernate mappings for Java basic types

Hibernate Mapping type

Java Type

Standard SQL type

Size and range of values

integer or int

int or java.lang.Integer

INTEGER

4 bytes

Long

Long Long

BIGINT

8 bytes

Short

Short Short

SMALLINT

2 bytes

Byte

BYTE byte

TINYINT

1 bytes

Float

float float

FLOAT

4 bytes

Double

Double Double

DOUBLE

8 bytes

Big_decimal

Java.math.BigDecimal

NUMERIC

NUMERIC (8,2) 8 -bit

Character

Char Character String

CHAR (1)

Fixed-length characters

String

String

VARCHAR

Variable length string

Boolean

Boolean Boolean

BIT

Boolean type

Yes_no

Boolean Boolean

CHAR (1) (y-n)

Boolean type

True_false

Boolean Boolean

CHAR (1) (T-F)

Boolean type

2. Hibernate mappings for Java time and date types

Mapping type

Java Type

Standard SQL type

Describe

Date

util. Date or sql. Date

DATE

Yyyy-mm-dd

Time

Date time

Time

HH:MM:SS

Timestamp

Date Timestamp

TIMESTAMP

Yyyymmddhhmmss

Calendar

Calendar

TIMESTAMP

Yyyymmddhhmmss

Calendar_date

Calendar

DATE

Yyyy-mm-dd

3. Types of hibernate mappings for Java large object types

style= "font-family: ' Times New Roman ';" >serializable interface arbitrary implementation class

TD valign= "Top" width= "

Map type

style= font-family Times New Roman '; " >java type

Standard sql type

mysql type

oracle type

binary

style= "font-family: ' Times New Roman ';" >byte[]

varbinary ( or blob)

blob

blob

text

style= "font-family: ' Times New Roman ';" >string

clob

text

clob

serializable

varbinary ( or blob)

blob

blob

clob

style= "font-family: ' Times New Roman ';" >java.sql.clob

style= "font-family: ' Times New Roman ';" >clob

text

clob

Blob

Java.sql.Blob

Blob

Blob

Blob

When you save a Java.sql.Clob or Java.sql.Blob instance through hibernate in your program, you must include two steps:

L Save an empty blob or CLOB instance in a database transaction first.

L then lock the record, update the saved blob or CLOB instance, and write the binary data or text data to the BLOB or CLOB instance.

4. Hibernate mapping type of individual Java classes with JDK (slightly)

5. Use hibernate built-in mapping type

Ii. Customized mapping type (slightly)

End!

Hibernate Tutorial-mapping types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.