Java 使用Uuid生成休眠
在这方面似乎有很多问题,但没有一个能解决我的问题 我正在尝试使用hibernate注释来生成UUID 我的注释如下Java 使用Uuid生成休眠,java,mysql,spring,hibernate,jpa,Java,Mysql,Spring,Hibernate,Jpa,在这方面似乎有很多问题,但没有一个能解决我的问题 我正在尝试使用hibernate注释来生成UUID 我的注释如下 @Id @GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy = "uuid") @Column(name = "uuid", unique = true) public UUID getUuid() { return uuid; } <bean
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
public UUID getUuid() {
return uuid;
}
<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>
我在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>
正确的注释是什么?我是否使用了错误的hibernate版本?我是否在MySQL中使用了错误的东西
我的方言详情如下
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
public UUID getUuid() {
return uuid;
}
<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>
org.hibernate.dialogue.mysqldialogue
org.hibernate.transaction.jdbc事务工厂
真的
创造
该错误意味着未指定长度,但如果我将其输入@Column,则不会发生任何更改
我只使用hibernate的旧版本,因为hibernate注释直到那时才更新,如果这是一个死的repo,我将移动到更高版本。我认为问题在于
getUuid()
方法返回的类型。根据hibernate文档,它需要是一个字符串
uuid:
使用128位UUID算法生成类型的标识符
网络中唯一的字符串(使用IP地址)。这个
UUID编码为长度为32位十六进制数字的字符串
啊,我也这么认为,但是从Hibernate 3.6开始,我认为他们支持UUID数据类型?阅读您在问题中指定的hibernate版本3.5。是的,链接的问题非常适用于hibernate 3.6Ah,对不起,我会编辑我的问题,如果我需要更新hibernate,我会非常乐意,但是从maven存储库来看,注释存储库只持续到3.5.6,这是一个死的回复吗?很好,看起来hibernate注释实际上不再需要了,我可以直接使用hibernate内核,非常感谢,它将更新到hibernate4。