You have this error because of @ManyToOne annotations inside your ComissionId class. To make this code work you have to move these relations to StoreComission class. In ComissionId class you should leave only identifiers. In StoreComission class @ManyToOne relation are mapped to the same columns as fields from composite key. But they have attributes 'insertable' and 'updateable' set to false to prevent column duplication.
Here is corrected working code for above scenario:
StoreComission class:
@Entity
public class StoreComission extends Model {
public StoreComission() {
id = new ComissionId();
}
@EmbeddedId
private ComissionId id;
@Column(nullable = false)
public double value;
@Column(nullable = false)
public Date date;
@ManyToOne
@JoinColumn(name = "booking_id", insertable = false, updatable = false)
private Booking booking;
@ManyToOne
@JoinColumn(name = "store_id", insertable = false, updatable = false)
private Store store;
public void setBooking(Booking aBooking) {
booking = aBooking;
id.booking_id = aBooking.id;
}
public Booking getBooking() {
return booking;
}
public void setStore(Store aStore) {
store = aStore;
id.store_id = aStore.id;
}
public Store getStore() {
return store;
}
}
ComissionId class:
@Embeddable
public class ComissionId {
public int booking_id;
public int store_id;
@Override
public int hashCode() {
return booking_id + store_id;
}
@Override
public boolean equals(final Object obj) {
return super.equals(obj);
}
}