Hibernate-Java-SQL type ing table and hibernate identity Generation Policy

Source: Internet
Author: User

I. hibernate-Java-SQL type ing table

Image version (easy to view ):


Table Version (easy to copy and paste ):

Basic hibernate type Java type Standard SQL Field Type Size/Description
Big_decimal Java. Math. bigdecimal Numeric Precision value (8 bits)
Binary Byte [] Varbinary, blob Variable-length binary data
Blob Java. SQL. blob Blob Binary data
Boolean Boolean/Java. Lang. Boolean Bit Boolean Type
Byte Byte/Java. Lang. byte Tinyint 1 byte
Calender Java. util. Calendar Timestamp Long date (yyyymmddhhmmss)
Calender_date Java. util. Calendar Date YYYY-MM-DD (short date)
Character Java. Lang. Character/Java. Lang. String/Char Char (1) Fixed Length character
Class Java. Lang. Class Varchar Variable-length characters
Clob Java. SQL. clob Clob Clob
Currency Java. util. Currency Varchar Fixed Length character
Date Java. util. Date/Java. SQL. Date Date Date
Double Double/Java. Lang. Double Double 8 bytes
Float Float/Java. Lang. Float Float 4 bytes
Interger INT/Java. langinteger Integer 4 bytes
Local Java. util. locale Varchar Variable-length characters
Long Long/Java. Lang. Long Bigint 8 bytes
Seralizable Java. Io. serializable and so on Varbinary, blob Variable-length binary data
Short Short/Java. Lang. Short Smallint 2 bytes
String Java. Lang. String Varchar Variable-length characters
Text Java. Lang. String Clob Large Character object
Time Java. util. Date/Java. SQL. Time Time Time (HH: mm: SS)
Timestamp Java. util. Date/Java. SQL. Timestamp Timestamp YYYY-MM-DD (short date)
Timezone Java. util. timezone Varchar Variable-length characters
True_false Boolean/Java. langboolean Char (1) ('T'/'F ') Boolean Type
Yes_no Boolean/Java. Lang. Boolean Char (1) ('y'/'n ') Boolean Type
Note: 1. considering that the operations on BLOB fields are too complicated, the technique of a transformation is. the object class uses the byte [] type, the hibernate type uses binary, and the database uses blob. this can simplify some operations; 2. type is of the string type. Because there is no text type in Java, the varchar type field and text type field in MySQL are both strings in the ing file in Java and the JavaBean field, but the length is limited, generally, the maximum length of text fields in the Java ing file is 65535.

I. hibernate identity Generation Policy

Image version (easy to view ):


Table Version (easy to copy and paste ):

Identifier Generator Description
Increment (incremental) Applies to the proxy primary key. It is automatically generated by hibernate in incremental mode. Used for long, short, or Int type. It can be used only when no other process inserts data into the same table. Do not use it in a cluster.
Identity Applies to the proxy primary key. The identifier generated by the underlying database. Supports built-in identity fields for DB2, MySQL, ms SQL Server, Sybase, and hypersonicsql. The returned identifier is of the long, short, or Int type.
Sequence) Applies to the proxy primary key. Hibernate generates identifiers Based on the sequence of the underlying database, which requires that the underlying database supports sequences. Sequence is used in DB2, PostgreSQL, Oracle, sap db, and mckoi, while generator is used in InterBase ). The returned identifier is of the long, short, or Int type.
HiLo (high/low) Applies to the proxy primary key. The identifier generated by the high/low algorithm of the hibernate branch. Use a high/low algorithm to efficiently generate long, short, or Int type identifiers. Specify a table and field (hibernate_unique_key and next_hi by default) as the source of high value. The inherent identifiers of high/low algorithms are unique only in a specific database. Do not use this native tool in the connection obtained by using JTA or the connection provided by the user.
Seqhilo (using the high and low bits of the sequence) Applies to the proxy primary key. Use a high/low-level algorithm to efficiently generate long, short, or Int type identifiers, and specify the name of a database sequence (sequence.
UUID. HEX Applies to the proxy primary key. Hibernate uses the 128-bit UUID algorithm to generate string-type identifiers. It is unique in a network (using an IP address ). UUID is encoded as a 32-bit hexadecimal number string.
UUID. String Applies to the proxy primary key. UUID is encoded into a 16-character string. The same UUID algorithm is used. UUID is encoded as a string consisting of 16 characters long and any ASCII characters. Cannot be used in a PostgreSQL database.
Native (local) Applies to the proxy primary key. Automatically select one of identity, sequence, or HiLo based on the method in which the underlying database automatically generates identifiers.
Assigned (program settings) Applicable to natural primary keys. The Java application is responsible for generating identifiers. Assign an identifier to the object before saving.
Foreign (External Reference) Applies to the proxy primary key. Use the identifier of another associated object.
Select Added in hibernate3. You must provide a unique identification field for secondary reading to obtain the inherent primary key value of the trigger and define it through the param sub-element. This method mainly targets legacy system transformation projects. Some early system primary keys rely on the trigger. When the database is inserted, the trigger captures this operation and assigns a value to the primary key. After inserting the data into the database, it reads a recognition field again to read the inserted data and obtain its primary key value.
Remarks: Composite primary key ing
<Composite-ID>
<Key-property? Column = "userid "? Name = "userid "? Type = "Java. Lang. String"> </key-property>
<Key-property? Column = "when "? Name = "when "? Type = "Java. SQL. Date"> </key-property>
</Composite-ID>
The pojo class of the composite primary key needs to implement the equals and hashcode methods, you can use the tool class implementation in the Apache commons lang Package (commons-lang.jar)

Iii. hibernate ing between Java time and date types

Hibernate ing type

Java type

Standard SQL type

Description

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

Related Article

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.