Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '184-174' for key 1 Error Code: 1062 Call: INSERT IGNORE INTO Activity_involves_BlockList (Block_ID, Activity_ID, LISTNAME, OWNERID) VALUES (?, ?, ?, ?) bind => [4 parameters bound] Query: DataModifyQuery(name="involvedBlockLists" sql="INSERT IGNORE INTO Activity_involves_BlockList (Block_ID, Activity_ID, LISTNAME, OWNERID) VALUES (?, ?, ?, ?)")
private Map<ListKey,Block> involvedBlockLists; @ManyToMany @JoinTable( name="Activity_involves_BlockList", joinColumns={ @JoinColumn(name="Activity_ID", referencedColumnName="ID")}, inverseJoinColumns={@JoinColumn(name = "Block_ID", referencedColumnName = "ID")} ) public Map<ListKey, Block> getInvolvedBlockLists() { return involvedBlockLists; } ..
@Embeddable public class ListKey implements Serializable { public ListKey() {} public ListKey(String listName, Long ownerId) { this.listName = listName; this.ownerId = ownerId; } private String listName; @Property public String getListName() { return listName; } public void setListName(String listName) { this.listName = listName; } private Long ownerId; @Property public Long getOwnerId() { return ownerId; } public void setOwnerId(Long ownerId) { this.ownerId = ownerId; } @Override public String toString() { return "ListKey: listName("+getListName()+"), ownerId("+getOwnerId()+")"; } @Override public boolean equals(Object o) { return Pojomatic.equals(this,o); } @Override public int hashCode() { return Pojomatic.hashCode(this); } }
private List<Activity> activitiesInvolvingLists; @ManyToMany(mappedBy="involvedBlockLists") public List<Activity> getActivitiesInvolvingLists() { return activitiesInvolvingLists; }
@Entity public class BlockListMapper extends All_ implements Serializable { private static final long serialVersionUID = 1L; private Long id; @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } private String listName; /** The property name of the mapped list. */ public String getListName() { return listName; } public void setListName(String listName) { this.listName = listName; } private Block block; @ManyToOne /** The owner of the mapped list */ public Block getBlock() { return block; } public void setBlock(Block block) { this.block = block; } private Element owner; @ManyToOne /** The owner of this list mapper (not the owner of the list) */ public Element getOwner() { return owner; } public void setOwner(Element owner) { this.owner = owner; } public BlockListMapper() {} public BlockListMapper(Element owner, Block block, String listName) { this.owner = owner; this.block = block; this.listName = listName; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof BlockListMapper)) { return false; } BlockListMapper other = (BlockListMapper) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Transient public Method getGetterForList() { try { String $i = "getGetterForList"; String $getter = "get" + StringHelper.upperFirst(listName); return block.getClass().getMethod($getter); } catch (NoSuchMethodException ex) { log_error(ex); } catch (SecurityException ex) { log_error(ex); } return null; } @Transient public List<Element> getListElements() { List l = new ArrayList<Element>(); for (Object o: getList()) { if (o instanceof Element) l.add((Element)o); } return l; } @Transient public List getList() { try { return (List) getGetterForList().invoke(block); } catch (IllegalAccessException ex) { log_error(ex); } catch (IllegalArgumentException ex) { log_error(ex); } catch (InvocationTargetException ex) { log_error(ex); } return null; } }