首页 > 技术文章 > hibernate、java、数据库对应类型

gcjava 2017-03-17 11:12 原文

引自 https://my.oschina.net/heau/blog/498874

java、数据库对应类型

类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述
           
VARCHAR L+N VARCHAR java.lang.String 12  
CHAR N CHAR java.lang.String 1  
BLOB L+N BLOB java.lang.byte[] -4  
TEXT 65535 VARCHAR java.lang.String -1  
           
INTEGER 4 INTEGER UNSIGNED java.lang.Long 4  
TINYINT 3 TINYINT UNSIGNED java.lang.Integer -6  
SMALLINT 5 SMALLINT UNSIGNED java.lang.Integer 5  
MEDIUMINT 8 MEDIUMINT UNSIGNED java.lang.Integer 4  
BIT 1 BIT java.lang.Boolean -7  
BIGINT 20 BIGINT UNSIGNED java.math.BigInteger -5  
FLOAT 4+8 FLOAT java.lang.Float 7  
DOUBLE 22 DOUBLE java.lang.Double 8  
DECIMAL 11 DECIMAL java.math.BigDecimal 3  
BOOLEAN 1 同TINYINT      
           
ID 11 PK (INTEGER UNSIGNED) java.lang.Long 4  
           
DATE 10 DATE java.sql.Date 91  
TIME 8 TIME java.sql.Time 92  
DATETIME 19 DATETIME java.sql.Timestamp 93  
TIMESTAMP 19 TIMESTAMP java.sql.Timestamp 93  
YEAR 4 YEAR java.sql.Date 91  
           

 

下面是hibernate官方文档给出的映射表:

 

Table 8.1. Basic Type Mappings

 

Hibernate type Database type JDBC type Type registry
org.hibernate.type.StringType string VARCHAR string, java.lang.String
org.hibernate.type.MaterializedClob string CLOB materialized_clob
org.hibernate.type.TextType string LONGVARCHAR text
org.hibernate.type.CharacterType char, java.lang.Character CHAR char  java.lang.Character
org.hibernate.type.BooleanType boolean BIT boolean   java.lang.Boolean
org.hibernate.type.NumericBooleanType boolean INTEGER, 0 is false, 1 is true numeric_boolean
org.hibernate.type.YesNoType boolean CHAR, 'N'/'n' is false, 'Y'/'y' is true. The uppercase value is written to the database. yes_no
org.hibernate.type.TrueFalseType boolean CHAR, 'F'/'f' is false, 'T'/'t' is true. The uppercase value is written to the database. true_false
org.hibernate.type.ByteType byte, java.lang.Byte TINYINT byte  java.lang.Byte
org.hibernate.type.ShortType short, java.lang.Short SMALLINT short   java.lang.Short
org.hibernate.type.IntegerTypes int, java.lang.Integer INTEGER int  java.lang.Integer
org.hibernate.type.LongType long, java.lang.Long BIGINT long   java.lang.Long
org.hibernate.type.FloatType float, java.lang.Float FLOAT float,  java.lang.Float
org.hibernate.type.DoubleType double, java.lang.Double DOUBLE double   java.lang.Double
org.hibernate.type.BigIntegerType java.math.BigInteger NUMERIC big_integer
org.hibernate.type.BigDecimalType java.math.BigDecimal NUMERIC big_decimal   java.math.bigDecimal
org.hibernate.type.TimestampType java.sql.Timestamp TIMESTAMP timestamp   java.sql.Timestamp
org.hibernate.type.TimeType java.sql.Time TIME time  java.sql.Time
org.hibernate.type.DateType java.sql.Date DATE date   java.sql.Date
org.hibernate.type.CalendarType java.util.Calendar TIMESTAMP calendar   java.util.Calendar
org.hibernate.type.CalendarDateType java.util.Calendar DATE calendar_date
org.hibernate.type.CurrencyType java.util.Currency VARCHAR currency  java.util.Currency
org.hibernate.type.LocaleType java.util.Locale VARCHAR locale  java.utility.locale
org.hibernate.type.TimeZoneType java.util.TimeZone VARCHAR, using the TimeZone ID timezone  java.util.TimeZone
org.hibernate.type.UrlType java.net.URL VARCHAR url  java.net.URL
org.hibernate.type.ClassType java.lang.Class VARCHAR, using the class name class  java.lang.Class
org.hibernate.type.BlobType java.sql.Blob BLOB blog   java.sql.Blob
org.hibernate.type.ClobType java.sql.Clob CLOB clob  java.sql.Clob
org.hibernate.type.BinaryType primitive byte[] VARBINARY binary  byte[]
org.hibernate.type.MaterializedBlobType primitive byte[] BLOB materized_blob
org.hibernate.type.ImageType primitive byte[] LONGVARBINARY image
org.hibernate.type.BinaryType java.lang.Byte[] VARBINARY wrapper-binary
org.hibernate.type.CharArrayType char[] VARCHAR characters  char[]
org.hibernate.type.CharacterArrayType java.lang.Character[] VARCHAR wrapper-characters  Character[], java.lang.Character[]
org.hibernate.type.UUIDBinaryType java.util.UUID BINARY uuid-binary, java.util.UUID
org.hibernate.type.UUIDCharType java.util.UUID CHAR, can also read VARCHAR uuid-char
org.hibernate.type.PostgresUUIDType java.util.UUID PostgreSQL UUID, through Types#OTHER, which complies to the PostgreSQL JDBC driver definition pg-uuid
org.hibernate.type.SerializableType implementors of java.lang.Serializable VARBINARY Unlike the other value types, multiple instances of this type are registered. It is registered once under java.io.Serializable, and registered under the specific java.io.Serializable implementation class names.

推荐阅读