пробую с простым составным ключем Код | @Entity @Table(name = "item_author_role") public class ItemAuthorRole implements Serializable { @Getter @Setter @EmbeddedId private ItemAuthorRoleId id; @Setter private Item item;
@MapsId("itemId") @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "item_id", referencedColumnName = "item_id") public Item getItem() { return item; }
@Override public boolean equals(Object obj) { return this == obj || obj != null && getClass() == obj.getClass(); }
@Override public int hashCode() { return new HashCodeBuilder(17, 31).append(item).toHashCode(); } }
@Embeddable class ItemAuthorRoleId implements Serializable { @Getter @Setter @Column(name = "item_id", nullable = false) private int itemId;
@Override public boolean equals(Object obj) { return this == obj || obj != null && getClass() == obj.getClass(); }
@Override public int hashCode() { return new HashCodeBuilder(17, 31).append(itemId).toHashCode(); } }
|
Item Код | @Entity @Table(name = "items") public class Item extends AbstractModel implements Serializable { @Setter private Set<ItemAuthorRole> itemAuthorRoleSet; @Setter private Technic technic;
{ itemAuthorRoleSet = new HashSet<>(0); }
@Override @SequenceGenerator(name = "isg", sequenceName = "item_sequence", initialValue = 1, allocationSize = 2) @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "isg") public Integer getId() { return super.getId(); }
@JoinColumn(name = "item_id", insertable = false, updatable = false) // это убирал, не влияет @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.DETACH}, mappedBy = "item", targetEntity = ItemAuthorRole.class) public Set<ItemAuthorRole> getItemAuthorRoleSet() { return itemAuthorRoleSet; }
@OneToOne @JoinColumn(name = "technic_id") public Technic getTechnic() { return technic; }
@Version @Column(name = "opt_lock") private Long version; }
|
ошибка Код | Exception [EclipseLink-48] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception Description: Multiple writable mappings exist for the field [item_author_role.item_id]. Only one may be defined as writable, all others must be specified read-only. Mapping: org.eclipse.persistence.mappings.OneToOneMapping[item] Descriptor: RelationalDescriptor(model.item.ItemAuthorRole --> [DatabaseTable(item_author_role)])
|
что не правильно ? спасибо
|