posted 16 years ago
hi all,
i have an entity mapping a table with a composite primary key: one of it's field is a foreign key who references another table's primary key.
I'm using jpa annotations, hibernate3, weblogic 9.2.
I would like use a generator to populate the foreign key,
i know how to do this for an entity with a simple primary key, but not with a composite key, i'm trying to do this with EmbeddedId and IdClass without any success (oracle says: cannot insert NULL into... )
here is entity (simplified) with IdClass:
@IdClass(EntityPK.class)
@Entity()
@Table(name="A_TABLE")
public class Entity implements Serializable {
private java.sql.Timestamp DDate;
private double qty;
private Objquantity objquantity;
private Long id;
private Timestamp DDate;
@Id
public Long getId() {
return this.id;
}
@Id
public java.sql.Timestamp getDDate() {
return this.DDate;
}
//many-to-one relationship
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="P_QTYID",referencedColumnName="P_QTYID",nullable=false, insertable=false, updatable=false)
public Objquantity getObjquantity () {
return this.objquantity ;
}
The PK Class:
public class EntityPK implements Serializable {
private Long id;
private Timestamp DDate;
@GenericGenerator(
name="idPKGenerator",
strategy="foreign",
parameters={
@Parameter(name="property", value="objquantity")
}
)
@Id
@GeneratedValue(generator="idPKGenerator")
@Column(name="ID", nullable=false, precision=22, insertable=false,updatable=false)
public Long getId() {
return this.id;
}
@Id
@Column(name="D_DATE", nullable=false, length=7)
public java.sql.Timestamp getDDate() {
return this.DDate;
}
Any suggest.
thanks in advance.