问题描述
事实证明,以下示例在使用mysql 5.x时可以工作,但在使用oracle 10g数据库时不会发生。
有没有办法定义一个独立于数据库技术的独特标识符字段?
$ $ $
@GeneratedValue(strategy = GenerationType。 IDENTITY)
@Column(name =id)
私人长ID;
我已经在hibernate中测试了这一点,只有在使用Oracle时才会出现以下异常:
org.hibernate.MappingException:Dialect不支持标识密钥生成
我研究过使用 GenerationType.AUTO
,它似乎是更好的选择。它允许JPA实现为您正在使用的数据存储系统选择最适合的数据。
It turns out that the following example works when using mysql 5.x, however it doesn't when using an oracle 10g database.
Is there a way to define a unique identifier field that is independent of the database technology?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private long id;
I have tested this in hibernate and the following exception occurs only when using Oracle:
org.hibernate.MappingException: Dialect does not support identity key generation
I have researched using GenerationType.AUTO
and it does appear to be the better option. It allows the JPA implementation to choose whatever is best for the data storage system you are using.
这篇关于定义独立于数据库的JPA对象uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!