合并在manyto许多实体挑起jointable
重复条目,我们有两个实体合并在manyto许多实体挑起jointable
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@Entity
@Table(name = "distributionlists", schema = "")
public class DistributionList implements Serializable
{
....
@ManyToMany(targetEntity = Contact.class)
@JoinTable(
name = "distributionlists_contacts",
joinColumns = @JoinColumn(name = "dl_id", referencedColumnName = "dl_id"),
inverseJoinColumns = @JoinColumn(name = "con_id", referencedColumnName = "con_id"))
private List<Contact> contacts;
}
和第二实体
@XmlRootElement @XmlType(name = "")
@Entity
@Table(name = "contacts", schema = "")
public class Contact implements Serializable
{
....
@ManyToMany(targetEntity = DistributionList.class, mappedBy = "contacts")
private List<DistributionList> distributionLists;
}
当我们做 em.merge(distributionList);
日食链接尝试复制在jointable
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.3.qualifier): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1-1' for key 'PRIMARY'
Error Code: 1062
Call: INSERT INTO distributionlists_contacts (con_id, dl_id) VALUES (?, ?)
bind => [2 parameters bound]
Query: DataModifyQuery(name="contacts" sql="INSERT INTO distributionlists_contacts (con_id, dl_id) VALUES (?, ?)")
.....
任何提示的条目?该实体应该是正确的,我们合并所有者部分
回答:
可能是您的List-s包含重复项。尝试将List的集合类型更改为Set。
以上是 合并在manyto许多实体挑起jointable 的全部内容, 来源链接: utcz.com/qa/266562.html