Saturday, 15 August 2015

java - Map part of composite PK to composite FK -


My data model contains items with history, I call an "instant" call in time; That's why all the tables have a "instant_id" that specifies how that item was configured on that instant "Instant_id" rolled into the entire primary key for all tables. Imagine the following example:

  Table Computer ============ PK Int Instant_ID & lt; - Shared ID PK int computer_id & lt; - Child ID int computer_type_id & lt; - Generator ID varchar foo Table Computer Type ================== PK Int Instant_ID & lt; - Shared ID PK Intel computer_type_id & lt; - Parent ID varchar bar  

In computer mapping (Instant_ID, computer_type_id), the computer type is a foreign key in the primary key.

We use some kind of

  @mbedded computerId {@column (name = 'quick_id', falsifiable = false) int instant_id, @column (name = 'Computer_id', tapable = false) Intel Computer_ID}  

then:

computer {@EmbeddedId ComputerId id; @MapsId ('instant_id') @ManyToOne @JoinColumn ({@JoinColumn (name = 'instant_id', ...), @JoinColumn (name = 'computer_type_id', ...)}) ComputerType computerType; }

No matter how I add MapsId with JoinIdColumn, I can not seem to do this work. Any ideas?

I can not find many organizations, you are not showing us how ComputerType < / Strong> has been declared, I am assuming that if it is a case if it is a matter, the definition per table you provided is Computer and ComputerType both Share an overall primary key: instant_id and computer_type_id .

If this is true and they share the same primary key, then you can do better by optimizing those two tables in one table as normal.


No comments:

Post a Comment