【发布时间】:2015-12-29 13:36:11
【问题描述】:
@Entity
@Table(name = "CONTACT_GROUP")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ContactGroup implements Serializable
{
private static final long serialVersionUID = 7161778136151592279L;
@Id
@GenericGenerator(name = "increment", strategy = "increment")
@GeneratedValue(generator = "increment")
@Column(name = "GRPOUP_ID")
private Long id;
@OneToMany(mappedBy="contactGroup",cascade = { CascadeType.ALL }, targetEntity = Contact.class)
Set<Contact> contacts;
}
@Entity
@Table(name = "CONTACT")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Contact implements Serializable
{
private static final long serialVersionUID = 7161778136151592279L;
@Id
@GenericGenerator(name = "increment", strategy = "increment")
@GeneratedValue(generator = "increment")
@Column(name = "CONTACT_ID")
Long id;
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid2")
@Column(name="group", unique=true)
String group;
@ManyToOne(cascade={CascadeType.ALL})
@JoinColumn(name = "GRPOUP_ID")
ContactGroup contactGroup;
}
你能告诉我上面的代码有什么问题没有自动增量
给出 ORA-00001:违反唯一约束
当我一次又一次地运行测试用例时
我如何生成它在第一条记录的空白值中插入的 uuid 值
请提前告诉我谢谢
【问题讨论】:
-
Oracle 不执行“自动增量”(即 JPA 策略“IDENTITY”)。您可以对 GeneratedValue 或“SEQUENCE”使用 JPA“TABLE”策略,因此很容易坚持 JPA 规范。你剩下的东西不是 JPA,Hibernate 特定的
-
我已经评论了这些行,即 /* @GenericGenerator(name = "increment", strategy = "increment") @GeneratedValue(generator = "increment")*/ 并尝试使用 @GeneratedValue(strategy = GenerationType.IDENTITY) 但给出以下错误 org.hibernate.MappingException: org.hibernate.dialect.Oracle10gDialect 不支持身份密钥生成
-
正如我上面已经说过的...... Oracle RDBMS 不支持“自动增量”(又名 JPA 策略 IDENTITY)。它将支持 TABLE 或 SEQUENCE,因此请使用其中之一!
标签: java oracle hibernate jpa spring-data-jpa