Hi,
I have two classes and a primaryKey class.
I'm Struggling with my foreign keys.
Code:
@Entity
@Table(name = "company")
public class Company {
@Id
private EffectiveDatePrimaryKey primaryKey = new EffectiveDatePrimaryKey();
private String name;
// ---------------------------- GETTERS + SETTERS
Code:
@Embeddable
public class EffectiveDatePrimaryKey implements Serializable{
private static final long serialVersionUID = 1L;
private long id;
private Date effectiveDate;
Code:
@Entity
@Table(name = "companyaddress")
public class CompanyAddress {
@Id
private EffectiveDatePrimaryKey primaryKey = new EffectiveDatePrimaryKey();
@ManyToOne
@JoinColumns ({
@JoinColumn(name="company_id", nullable=false)
})
private Company company;
In my companyAddress:
- I only want to store the company_id.
- The effectiveDate of the company is not needed, because I only use it to store historical data
I know a ManyToOne needs a unique reference to a parent table.
I want to make the reference unique with the use of a FilterDef
Thanks in advance,
Pieter Pareit