-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: composite primary key mapping
PostPosted: Tue Sep 02, 2008 3:33 am 
Newbie

Joined: Thu Aug 14, 2008 2:22 am
Posts: 11
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 6:25 am 
Newbie

Joined: Mon Nov 24, 2008 6:15 am
Posts: 1
I'm having this problem as well and all my forum/JIRA searches seem to be dead ends. Did Hibernate ever solve this problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.