我使用@GeneratedValue(strategy = GenerationType.AUTO)在我的實體上生成ID。oracle上的休眠序列,@GeneratedValue(strategy = GenerationType.AUTO)
我現在不知道它是如何工作的,但在我的子表上,生成了遵循父順序的ID值。
//parent table
@Entity
@Table (name = "parent")
public class Parent {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@Column (name = "id")
private long id;
@OneToMany (cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn (name = "parentId")
@ForeignKey (name = "FKparent")
private List<child> child;
}
//child table
@Entity
@Table (name = "child")
public class Child {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@Column (name = "id")
private long id;
}
在父級上插入的ID值更新序列。 孩子上插入的ID值,更新序列。 對於父代的下一個插入,序列...使用由子插入更新的值...
此批註不創建兩個序列,只有一個。這是正確的/預期的?
我插入我的實體吾道服務只使用entityManager.persist(parent);
若最終用戶看到該密鑰和由它被誤導「神經質」。不要告訴我,關鍵需要隱藏的用戶,這並不總是可能的... – Monoman 2012-02-27 18:54:35
有沒有辦法保持ids恆定的時間和單調,沒有漏洞的序列,這並不殺可擴展性。我也沒有看到'jumpy'的有用定義以及爲什麼用戶需要unjumpy ID。 – 2012-02-28 06:48:24