簡體   English   中英

Hibernate使用Uuid生成

[英]Hibernate using Uuid generation

似乎有很多問題,但沒有解決我的問題。

我正在嘗試使用hibernate注釋來生成UUID。

我的注釋低於......

@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
public UUID getUuid() {
    return uuid;
}

我在我的pom.xml中使用MySQL 5.2和Hibernate 3.5.6,如下所示......

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>

啟動我的應用程序后,我收到以下錯誤...

ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table players (uuid tinyblob not null unique, espnid integer, espnUrl varchar(255), firstname varchar(255), lastname varchar(255), primary key (uuid))
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - BLOB/TEXT column 'uuid' used in key specification without a key length

什么是正確的注釋? 我使用的是不正確的休眠版本嗎? 我是否在使用MySQL時出錯?

我的方言細節如下......

<beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                </beans:prop>
                <beans:prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory
                </beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
                <beans:prop key="hibernate.hbm2ddl.auto">create</beans:prop>
            </beans:props>
        </beans:property>

該錯誤意味着未指定長度,但如果我將其輸入@Column則沒有任何更改。

我只使用舊版本的hibernate,因為hibernate-annotations只會到那時為止,如果現在這是一個死的回購,我將轉移到更高版本。

我認為問題是getUuid()方法返回的類型。 根據hibernate文檔,它需要是一個String

UUID:

使用128位UUID算法生成在網絡中唯一的字符串類型的標識符(使用IP地址)。 UUID編碼為長度為32個十六進制數字的字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM