情况就是这样:我有一个映射表,我们称之为SecurityContact,有三列。
基本上,这个SecurityContact表将agent_id和audit_id连接到security_id。 agent_id和audit_id可以相同或不同,具体取决于AgentContact中的两个条目是相同还是不同。
现在问题就在于:即使两个条目不同,Hibernate似乎也为它们都设置了相同的id,这个id是SecurityContact的auditContact的contact_id。这两个条目应该不同,agent_id包含代理的contact_id,audit_id包含审计的contact_id(来自同一个表,AgentContact)。任何人都知道为什么?
我为这么长时间的啰嗦而道歉。以下是SecurityContact的代码:
/**
* The persistent class for the SecurityContact database table.
*
*/
@Entity
@FXClass(kind=FXClassKind.REMOTE)
public class SecurityContact implements Serializable {
private static final long serialVersionUID = 1L;
@Transient private String uid;
@FXIgnore
public String getUid() {
if (uid == null) {
uid = "" + securityId;
}
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="security_id")
private Long securityId;
@Column(name="create_date")
private String createDate;
@Column(name="create_user")
private String createUser;
@Column(name="modify_date")
private String modifyDate;
@Column(name="modify_user")
private String modifyUser;
//bi-directional many-to-one association to AgentContact
@ManyToOne
@JoinColumn(name="agent_id", referencedColumnName="contact_id")
private AgentContact agentContact;
//bi-directional many-to-one association to AuditContact
@ManyToOne
@JoinColumn(name="audit_id", referencedColumnName="contact_id")
private AgentContact auditContact;
public SecurityContact() {
}
@FXKeyColumn
public Long getSecurityId() {
return this.securityId;
}
public void setSecurityId(Long securityId) {
this.securityId = securityId;
}
public String getCreateDate() {
return this.createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public String getCreateUser() {
return this.createUser;
}
public void setCreateUser(String createUser) {
this.createUser = createUser;
}
public String getModifyDate() {
return this.modifyDate;
}
public void setModifyDate(String modifyDate) {
this.modifyDate = modifyDate;
}
public String getModifyUser() {
return this.modifyUser;
}
public void setModifyUser(String modifyUser) {
this.modifyUser = modifyUser;
}
@FXManyToOne(parent="com.counterpartcontacts.entity.AgentContact", property="contactId")
public AgentContact getAgentContact() {
return this.agentContact;
}
public void setAgentContact(AgentContact agentContact) {
this.agentContact = agentContact;
}
@FXManyToOne(parent="com.counterpartcontacts.entity.AgentContact", property="contactId")
public AgentContact getAuditContact() {
return this.auditContact;
}
public void setAuditContact(AgentContact auditContact) {
this.auditContact = auditContact;
}
}
以下是AgentContact表的代码:
/**
* The persistent class for the AgentContact database table.
*
*/
@Entity
@FXClass(kind=FXClassKind.REMOTE)
public class AgentContact implements Serializable {
private static final long serialVersionUID = 1L;
@Transient private String uid;
@FXIgnore
public String getUid() {
if (uid == null) {
uid = "" + contactId;
}
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="contact_id")
private Long contactId;
@ManyToOne
@JoinColumn(name="bank_id")
private Bank bank;
// @Column(name="bank_id")
//private String bank2;
@Column(name="create_date")
private String createDate;
@Column(name="create_user")
private String createUser;
private String email;
private String fax;
@Column(name="modify_date")
private String modifyDate;
@Column(name="modify_user")
private String modifyUser;
private String name;
private String phone;
//bi-directional many-to-one association to SecurityContact
@OneToMany(mappedBy="agentContact")
private Set<SecurityContact> securityContacts;
public AgentContact() {
}
@FXKeyColumn
public Long getContactId() {
return this.contactId;
}
public void setContactId(Long contactId) {
this.contactId = contactId;
}
@FXManyToOne(parent="com.counterpartcontacts.entity.Bank", property="bankId")
public Bank getBank() {
return this.bank;
}
public void setBank(Bank bank) {
this.bank = bank;
}
public String getCreateDate() {
return this.createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public String getCreateUser() {
return this.createUser;
}
public void setCreateUser(String createUser) {
this.createUser = createUser;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFax() {
return this.fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getModifyDate() {
return this.modifyDate;
}
public void setModifyDate(String modifyDate) {
this.modifyDate = modifyDate;
}
public String getModifyUser() {
return this.modifyUser;
}
public void setModifyUser(String modifyUser) {
this.modifyUser = modifyUser;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@FXOneToMany(fillArguments="contactId")
public Set<SecurityContact> getSecurityContacts() {
return this.securityContacts;
}
public void setSecurityContacts(Set<SecurityContact> securityContacts) {
this.securityContacts = securityContacts;
}
}