Hello together,
I want to create the following:
CREATE TABLE
PreviousStorageLocation (
SerialNumber VARCHAR(50) NOT NULL,
PartNumber VARCHAR(50) NOT NULL,
TracingDate DATETIME NOT NULL,
TracingTimeZone VARCHAR(100) NOT NULL,
PRIMARY KEY (SerialNumber, PartNumber,TracingDate, TracingTimeZone),
FOREIGN KEY (SerialNumber, PartNumber) REFERENCES Part (SerialNumber, PartNumber) ON DELETE CASCADE ON UPDATE CASCADE,
) Type=InnoDB;
CREATE TABLE
Part (
SerialNumber VARCHAR(50) NOT NULL,
PartNumber VARCHAR(50) NOT NULL,
LogState VARCHAR(16) NOT NULL,
Availability VARCHAR(16) NOT NULL,
PRIMARY KEY (SerialNumber, PartNumber),
FOREIGN KEY (PartNumber) REFERENCES GenericPartSpecification (PartNumber) ON DELETE CASCADE ON UPDATE CASCADE
) Type=InnoDB;
My problem is that i can't map the composite key SerialNumber, PartNumber from table Part to an composite key in PreviousStorageLocation.
This ist what I did. But that throws an AnnotationException: A Foreign key refering de.fhg.atl.javabeans.Part from de.fhg.atl.javabeans.PreviousStorageLocation has the wrong number of column. should be 2
Part:
Code:
@Entity
@Table(name="Part")
@AssociationOverrides({
@AssociationOverride(name="partId.genericPartSpecification", joinColumns = @JoinColumn(name="PartNumber"))
})
public class Part {
@Id
private PartId partId = new PartId();
@SuppressWarnings("unused")
@Column(name="PartNumber", updatable=false, insertable=false, nullable=false)
private String genericPartSpecification;
...
}
PartId:
Code:
@Embeddable
public class PartId implements Serializable {
@Column(name="SerialNumber")
private String serialNumber;
@ManyToOne
private GenericPartSpecification genericPartSpecification;
...
PreviousStorageLocation
Code:
@Entity
@Table(name="PreviousStorageLocation")
@AssociationOverrides({
@AssociationOverride(name="previousStorageLocationId.part", joinColumns = @JoinColumn(name="SerialNumber"))
})
public class PreviousStorageLocation implements Comparable<PreviousStorageLocation> {
@Id
private PreviousStorageLocationId previousStorageLocationId= new PreviousStorageLocationId();
@SuppressWarnings("unused")
@Columns(columns={@Column(name="SerialNumber", updatable=false, insertable=false, nullable=false),
@Column(name="PartNumber", updatable=false, insertable=false, nullable=false)})
private String part;
...
PreviousStorageLocationId:
Code:
@Embeddable
public class PreviousStorageLocationId implements Serializable
{
@Column(name="TracingDate")
private Date tracingDate;
@Column(name="TracingTimeZone")
private String tracingTimeZoneID;
@ManyToOne
@JoinColumns({
@JoinColumn(name="PartNumber", referencedColumnName= "partNumber"),
@JoinColumn(name= "SerialNumber", referencedColumnName="serialNumber")
})
private Part part;
...
Does anyone know how to map a composite primary key to another composite primary key?
Thanks for help
Alex