我有兩個表。複合主鍵選擇 - Hibernate的哪些功能不適用於EclipseLink。爲什麼?
CREATE TABLE profile_table
(
profile_id NUMBER(10,0) PRIMARY KEY,
creator_manager_id NUMBER(10,0),
lastupdate DATE,
description VARCHAR2(255 BYTE),
profile_name VARCHAR2(255 BYTE),
creatorname VARCHAR2(255 BYTE)
);
CREATE TABLE profile_basket_table
(
profile_id NUMBER(10,0),
from_id NUMBER(10,0),
action NUMBER(10,0),
constraint pbt_pk_constraint PRIMARY KEY(profile_id, from_id),
constraint pbt_fk_constraint FOREIGN KEY(profile_id) REFERENCES profile_table(profile_id)
);
我有1個配置文件和* ProfileItem。
1配置文件--- * ProfileItems(一個配置文件可以有許多ProfileItems)。
注意:1.它是一個從profile到profileItem的一對多關係。 2.它是一種單向關係。
配置文件的PK是profile_id。
的PK ProfileItem是一個複合主鍵(PROFILE_ID,from_id)
首先,我想我喜歡抱怨的EclipseLink不工作,如Hibernate:
1日問題與EclipseLink的: 只是becasue我有一個名爲ProfileItem的子實體中的複合主鍵,它迫使我使用JoinColumns。我不能使用@JoinColumns作爲其他列from_id不是任何其他表的外鍵。
@Entity
@Table(name="profile_table")
class Profile {
@Id
@Column(name="profile_id")
private Integer profileId ;
...
/**
* WORKS WITH HIBERNATE AS PERSISTENCE PROVIDER, BUT FAILS WITH ECLIPSELINK
*/
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name= "profile_id", referencedColumnName="profile_id")
private Set<XVMUpdateProfileItem> profileItems = null;
...
}
以上代碼拋出下面的錯誤與EclipseLink的: 我最初使用與Hibernate的完美工作如下相同註釋
The @JoinColumns on the annotated element [field profileItems] from the entity class [class arun.ucerelay.datastructures.XVMUpdateProfile] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
一些如何與幾個排列@JoinColumn註解的組合,我管理讓這個工作負載配置文件和相關的配置文件項目。
/**
* WORKS WITH ECLIPSELINK AS PERSISTENCE PROVIDER
*/
@OneToMany(cascade = CascadeType.ALL)
@JoinColumns({
@JoinColumn(name= "profile_id", referencedColumnName="profile_id" , insertable = true, updatable = true),
@JoinColumn(name= "profile_id", referencedColumnName="profile_id" , nullable = false)
})
private Set<XVMUpdateProfileItem> profileItems = null;
這沒有意義再次聲明@JoinColumn ...但奇怪的是它與eclipselink工作。這是一個錯誤。不是嗎?
任何人都可以告訴我,如果我失去了什麼?有沒有其他正確的方式來實現單向關係,請告訴我。
這是一個關於@JoinColumns的bug嗎?我應該登錄嗎?
這就是所謂的「便攜性」從一個持久性提供者到另一個??????? 如果它不解決可移植性,那麼使用JPA規範有什麼用處。
保存父級和級聯子項的第二個問題與休眠一起使用,並且不適用於eclipselink。我把它作爲一個單獨的問題發佈,以保持簡潔和精確。
謝謝。 Arun Kandregula
作爲參考,DataNucleus將(http://www.datanucleus.org)適用於該元數據細;只有一個@JoinColumn,因爲這是識別ProfileItem中鏈接回配置文件(具有單個PK字段)的FK。 – DataNucleus 2011-04-02 14:38:49