[英]Hibernate using Uuid generation
There seems to be quite a few questions on this, but none resolve my issue. 似乎有很多问题,但没有解决我的问题。
I'm trying to use hibernate annotations to generate a UUID. 我正在尝试使用hibernate注释来生成UUID。
My annotations are below... 我的注释低于......
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
public UUID getUuid() {
return uuid;
}
I'm using MySQL 5.2 with Hibernate 3.5.6 in my pom.xml as shown below... 我在我的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>
Upon starting my application, I get the following error... 启动我的应用程序后,我收到以下错误...
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
What's the correct annotation? 什么是正确的注释? Am I using an incorrect hibernate version?
我使用的是不正确的休眠版本吗? Am I using something incorrectly with MySQL?
我是否在使用MySQL时出错?
My dialect details are below... 我的方言细节如下......
<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>
The error implies the length isn't specified, but if I enter this into @Column nothing changes. 该错误意味着未指定长度,但如果我将其输入@Column则没有任何更改。
I'm only using an older version of hibernate due to the hibernate-annotations only going up till then, if this is now a dead repo I'll move to a later version. 我只使用旧版本的hibernate,因为hibernate-annotations只会到那时为止,如果现在这是一个死的回购,我将转移到更高版本。
I think the problem is the type returned by the getUuid()
method. 我认为问题是
getUuid()
方法返回的类型。 It needs to be a String
according to hibernate docs. 根据hibernate文档,它需要是一个
String
。
uuid:
UUID:
uses a 128-bit UUID algorithm to generate identifiers of type string that are unique within a network (the IP address is used).
使用128位UUID算法生成在网络中唯一的字符串类型的标识符(使用IP地址)。 The UUID is encoded as a string of 32 hexadecimal digits in length.
UUID编码为长度为32个十六进制数字的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.