• hibernate映射对照表


    2.3. Basic Types

    Basic value types usually map a single database column, to a single, non-aggregated Java type. Hibernate provides a number of built-in basic types, which follow the natural mappings recommended by the JDBC specifications.

    Internally Hibernate uses a registry of basic types when it needs to resolve a specific org.hibernate.type.Type.

    2.3.1. Hibernate-provided BasicTypes

    Table 1. Standard BasicTypes
    Hibernate type (org.hibernate.type package)JDBC typeJava typeBasicTypeRegistry key(s)

    StringType

    VARCHAR

    java.lang.String

    string, java.lang.String

    MaterializedClob

    CLOB

    java.lang.String

    materialized_clob

    TextType

    LONGVARCHAR

    java.lang.String

    text

    CharacterType

    CHAR

    char, java.lang.Character

    char, java.lang.Character

    BooleanType

    BIT

    boolean, java.lang.Boolean

    boolean, java.lang.Boolean

    NumericBooleanType

    INTEGER, 0 is false, 1 is true

    boolean, java.lang.Boolean

    numeric_boolean

    YesNoType

    CHAR, 'N'/'n' is false, 'Y'/'y' is true. The uppercase value is written to the database.

    boolean, java.lang.Boolean

    yes_no

    TrueFalseType

    CHAR, 'F'/'f' is false, 'T'/'t' is true. The uppercase value is written to the database.

    boolean, java.lang.Boolean

    true_false

    ByteType

    TINYINT

    byte, java.lang.Byte

    byte, java.lang.Byte

    ShortType

    SMALLINT

    short, java.lang.Short

    short, java.lang.Short

    IntegerTypes

    INTEGER

    int, java.lang.Integer

    int, java.lang.Integer

    LongType

    BIGINT

    long, java.lang.Long

    long, java.lang.Long

    FloatType

    FLOAT

    float, java.lang.Float

    float, java.lang.Float

    DoubleType

    DOUBLE

    double, java.lang.Double

    double, java.lang.Double

    BigIntegerType

    NUMERIC

    java.math.BigInteger

    big_integer, java.math.BigInteger

    BigDecimalType

    NUMERIC

    java.math.BigDecimal

    big_decimal, java.math.bigDecimal

    TimestampType

    TIMESTAMP

    java.sql.Timestamp

    timestamp, java.sql.Timestamp

    TimeType

    TIME

    java.sql.Time

    time, java.sql.Time

    DateType

    DATE

    java.sql.Date

    date, java.sql.Date

    CalendarType

    TIMESTAMP

    java.util.Calendar

    calendar, java.util.Calendar

    CalendarDateType

    DATE

    java.util.Calendar

    calendar_date

    CalendarTimeType

    TIME

    java.util.Calendar

    calendar_time

    CurrencyType

    java.util.Currency

    VARCHAR

    currency, java.util.Currency

    LocaleType

    VARCHAR

    java.util.Locale

    locale, java.utility.locale

    TimeZoneType

    VARCHAR, using the TimeZone ID

    java.util.TimeZone

    timezone, java.util.TimeZone

    UrlType

    VARCHAR

    java.net.URL

    url, java.net.URL

    ClassType

    VARCHAR (class FQN)

    java.lang.Class

    class, java.lang.Class

    BlobType

    BLOB

    java.sql.Blob

    blog, java.sql.Blob

    ClobType

    CLOB

    java.sql.Clob

    clob, java.sql.Clob

    BinaryType

    VARBINARY

    byte[]

    binary, byte[]

    MaterializedBlobType

    BLOB

    byte[]

    materized_blob

    ImageType

    LONGVARBINARY

    byte[]

    image

    WrapperBinaryType

    VARBINARY

    java.lang.Byte[]

    wrapper-binary, Byte[], java.lang.Byte[]

    CharArrayType

    VARCHAR

    char[]

    characters, char[]

    CharacterArrayType

    VARCHAR

    java.lang.Character[]

    wrapper-characters, Character[], java.lang.Character[]

    UUIDBinaryType

    BINARY

    java.util.UUID

    uuid-binary, java.util.UUID

    UUIDCharType

    CHAR, can also read VARCHAR

    java.util.UUID

    uuid-char

    PostgresUUIDType

    PostgreSQL UUID, through Types#OTHER, which complies to the PostgreSQL JDBC driver definition

    java.util.UUID

    pg-uuid

    SerializableType

    VARBINARY

    implementors of java.lang.Serializable

    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.

    StringNVarcharType

    NVARCHAR

    java.lang.String

    nstring

    NTextType

    LONGNVARCHAR

    java.lang.String

    ntext

    NClobType

    NCLOB

    java.sql.NClob

    nclob, java.sql.NClob

    MaterializedNClobType

    NCLOB

    java.lang.String

    materialized_nclob

    PrimitiveCharacterArrayNClobType

    NCHAR

    char[]

    N/A

    CharacterNCharType

    NCHAR

    java.lang.Character

    ncharacter

    CharacterArrayNClobType

    NCLOB

    java.lang.Character[]

    N/A

    Table 2. BasicTypes added by hibernate-java8
    Hibernate type (org.hibernate.type package)JDBC typeJava typeBasicTypeRegistry key(s)

    DurationType

    BIGINT

    java.time.Duration

    Duration, java.time.Duration

    InstantType

    TIMESTAMP

    java.time.Instant

    Instant, java.time.Instant

    LocalDateTimeType

    TIMESTAMP

    java.time.LocalDateTime

    LocalDateTime, java.time.LocalDateTime

    LocalDateType

    DATE

    java.time.LocalDate

    LocalDate, java.time.LocalDate

    LocalTimeType

    TIME

    java.time.LocalTime

    LocalTime, java.time.LocalTime

    OffsetDateTimeType

    TIMESTAMP

    java.time.OffsetDateTime

    OffsetDateTime, java.time.OffsetDateTime

    OffsetTimeType

    TIME

    java.time.OffsetTime

    OffsetTime, java.time.OffsetTime

    OffsetTimeType

    TIMESTAMP

    java.time.ZonedDateTime

    ZonedDateTime, java.time.ZonedDateTime

     

    To use these hibernate-java8 types just add the hibernate-java8 dependency to your classpath and Hibernate will take care of the rest. See Mapping Date/Time Values for more about Java 8 Date/Time types.

    These mappings are managed by a service inside Hibernate called the org.hibernate.type.BasicTypeRegistry, which essentially maintains a map of org.hibernate.type.BasicType (a org.hibernate.type.Type specialization) instances keyed by a name. That is the purpose of the "BasicTypeRegistry key(s)" column in the previous tables.

  • 相关阅读:
    模拟打车
    atm转账
    python字符串,列表,字典,集合的常用方法
    while和for的简单使用
    数据库的基本命令
    jmeter监控linux的性能
    jmeter的错误解决Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
    jmeter的正则参数化
    jmeter的参数化关联
    使用Python解析JSON
  • 原文地址:https://www.cnblogs.com/bmbi/p/5247584.html
Copyright © 2020-2023  润新知