I'm using Hibernate Entity Manager 3.3.2 and am trying to create a bi-directional OneToMany association with the OneToMany side being the owning side. My two tables are set up like so:
Table 1
APPID primary key generated by a sequence on the database
Table 2
APPID foreign key to Table 1 and part of primary key
OFF_NO part of primary key
OFF_BANK part of primary key
Table 1 Entity looks like this
Code:
public class AppDetails implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="APP_ID_GEN", sequenceName="PTS_APP_DTL_APPID_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="APP_ID_GEN")
private long appid;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="APPID", nullable=false)
@org.hibernate.annotations.Cascade({
org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN
})
private Set<OfficerDetails> ptsOfficerDetails = new HashSet<OfficerDetails>();
...
}
Table 2 entity looks like this:
Code:
public class OfficerDetails implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private OfficerDetailsPK id;
@ManyToOne
@JoinColumn(name="APPID", insertable=false, updatable=false, nullable=false)
private AppDetails ptsAppDetail;
...
}
OfficerDetailsPK looks like:
Code:
@Embeddable
public class OfficerDetailsPK implements Serializable {
private static final long serialVersionUID = 1L;
private long appid;
@Column(name="OFF_BANK")
private String offBank;
@Column(name="OFF_NO")
private String offNo;
...
}
I'm getting the following error when a save is done on my Table 1 entity:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): OfficerDetails
I don't think my bi-directional annotations are quite right. Any help is greatly appreciated.