我的某個實體有問題。EclipseLink:在ManyToMany-關係中刪除時Column的值爲空
有3個用於GlassFish訪問管理的表(UserAccount,UserRole,Role)和兩個由「ManyToMany」映射到彼此的實體UserAccount和Role。
要更改UserAccount的角色,我通過setRoles() - UserAccount方法應用所選角色的新列表。當我添加新的角色,一切正常,該聲明是正確的:
INSERT INTO UserRole (Role_roleName, UserAccount_email,
UserAccount_Account_accountId)
VALUES ('Client', '[email protected]', 1)
但是,當我從列表中刪除的項,在連接表中刪除條目也應該被刪除。如預期的那樣,提交了查詢,但電子郵件列設置爲「空」。
DELETE FROM UserRole WHERE ((Role_roleName = 'Administrator')
AND ((UserAccount_Account_accountId = 1) AND (UserAccount_email = null)))
有沒有人知道爲什麼這個列設置爲null?當我輸出電子郵件與userAccount.getEmail()之前和之前合併到數據庫,它返回電子郵件地址...
任何幫助,非常感謝。
感謝,曼努埃爾
設置: 容器:Glassfish的3.1.2 JPA:Eclipse持久服務 - 2.3.2.v20111125-r10461
UserAccount實體:
@Entity
@Table(name="UserAccount")
@PrimaryKeyJoinColumn(name = "Account_accountId")
public class UserAccount extends Account implements Serializable {
private static final long serialVersionUID = 1L;
private String password;
//bi-directional one-to-one association to Account
@OneToOne
@JoinColumn(name="Account_accountId")
private Account account;
@Column(name="email")
private String email;
//bi-directional many-to-many association to Role
@ManyToMany
@JoinTable(
name="UserRole"
,
joinColumns={
@JoinColumn(name="UserAccount_email", referencedColumnName="email"),
@JoinColumn(name="UserAccount_Account_accountId", referencedColumnName="Account_accountId")
}
, inverseJoinColumns={
@JoinColumn(name="Role_roleName")
}
)
private List<Role> roles;
//getter and setters
帳戶實體
@Entity
@Table(name="Account")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Account implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int accountId;
private boolean active;
private String address;
private String dtype;
private String firstname;
private String handy;
private String name;
private String tel;
//getter and setters
角色實體:
@Entity
@Table(name="Role")
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String roleName;
@Lob
private String roleDescription;
//bi-directional many-to-many association to UserAccount
@ManyToMany(mappedBy="roles")
private List<UserAccount> userAccounts;
//getter and setters
你是如何解決這個問題的? – 2013-05-24 17:38:47
不幸的是我無法解決它... – Manuel 2013-05-26 12:27:01
只要我找到解決方案,我會告訴你。 – 2013-05-28 13:43:09