I am having trouble setting up jpa mappings for some entities. I have a parent entity defined like the following.
@Entity
@Table(name="EIF_INSTANCE_HDR")
public class InstanceEntity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator="eif_inst_gen")
@SequenceGenerator(name="eif_inst_gen",sequenceName="EIF_INSTANCE_SEQ")
@Column(name = "EAIH_ID")
private Long eaihid;
@Column(name = "EAD_ID")
private Long eadid;
@OneToMany(targetEntity=InstanceNotifyEntity.class, mappedBy="instance",fetch=FetchType.EAGER, cascade = CascadeType.ALL)
private List<InstanceNotifyEntity> userDetails = new ArrayList<InstanceNotifyEntity>();
}
I then have a child entity w/ a composite key, and a foreign key to the primary key of this table as follows:
@Entity
@Table(name="EIF_INST_NOTIFIED")
public class InstanceNotifyEntity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@ManyToOne
@JoinColumn(name="EAIH_ID", referencedColumnName="EAIH_ID")
private InstanceEntity instance;
@Id
@Column(name="USER_ID")
private Long userId;
@Column(name="COMMENT_TXT")
private String commentText;
}
I know the child entity is incorrect, but I am unsure how to set this up to have a composite PK. I know I need to setup a PK class, but I am not sure how to do that when one field is a foreign key to the parent class. And once that is setup how would the parent reference the child entity?
Any help is appreciated.