I have two tables:
Order 1: n OrderDetail (one-to-many unidirectional relationship)
OrderEntity and OrderDetailEntity both extend a superclass BaseEntity:
Code:
@MappedSuperclass
@Inheritance
public abstract class BaseEntity {
@EmbeddedId
private BaseEntityPK compPK;
//getters and setters
The embedded class:
Code:
@Embeddable
@Inheritance
public class BaseEntityPK implements Serializable {
@Column(name="CLIENT_KEY", nullable = false)
private long clientKey;
@Column(name = "GUID", nullable = false)
private long guid;
public BaseEntityPK() {
}
public long getClientKey() {
return this.clientKey;
}
public void setClientKey(long clientKey) {
this.clientKey = clientKey;
}
public long getGuid() {
return this.guid;
}
public void setGuid(long guid) {
this.guid = guid;
}
public BaseEntityPK(long clientKey, long guid) {
this.clientKey = clientKey;
this.guid = guid;
}
}
The OrderEntity entity:
Code:
@Entity
@Table(name="ORDERS")
public class OrderEntity extends BaseEntity implements Serializable {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumns
({@JoinColumn(name = "ORDERIDCLIENTGUID", referencedColumnName = "CLIENTGUID", nullable = false),
@JoinColumn(name = "CLIENT_KEY", referencedColumnName = "CLIENT_KEY", nullable = false)
})
private Set<OrderDetailEntity> orderDetails = new HashSet<>();
//getters and setters
Code:
The OrderDetailEntity entity:
@Entity
@Table(name="ORDERDETAIL")
public class OrderDetailEntity extends BaseEntity implements Serializable {
//getters and setters
For both Orders and OrderDetail tables:
CLIENT_KEY and GUID columns represent the primary key
CLIENT_KEY and CLIENTGUID represent an unique key.
If I use the mappings above, I get the following exception:
Code:
Caused by: org.hibernate.AnnotationException: referencedColumnNames(CLIENTGUID, CLIENT_KEY) of ...entities.OrderDetailEntity.orderDetails referencing ...entities.OrderEntity not mapped to a single property
Is the a way in hibernate to join two tables after a foreign key column and a partial primary key column?