EmbeddedId)
Master Table
@ Entity
Public class A implements Serializable ...{
@ EmbeddedId
Private AId aId;
Public AId getAId ()...{
Return aId;
}
Public void setAId (AId aId )...{
This. aId = aId;
}
}
Composite primary key
@ Embeddable
Public class AId implements Serializable ...{
@ OneToOne
@ JoinColumn (name = "bid ")
Private B;
@ OneToOne
@ JoinColumn (name = "cid ")
Private C c;
Public B getB ()...{
Return B;
}
Public void setB (B B )...{
This. B = B;
}
Public C getC ()...{
Return c;
}
Public void setC (C c )...{
This. c = c;
}
}
Join table
@ Entity
Public class B ...{
@ Id
@ GeneratedValue
Private Long id;
Public Long getId ()...{
Return id;
}
Public void setId (Long id )...{
This. id = id;
}
}
@ Entity
Public class C ...{
@ Id
@ GeneratedValue
Private Long id;
Public Long getId ()...{
Return id;
}
Public void setId (Long id )...{
This. id = id;
}
}
Application of compound primary key (IdClass)
Master Table
@ Entity
@ IdClass (OrderLinePk. class)
Public class OrderLine ...{
@ Id
Public Order order;
@ Id
Public Product product;
}
Primary key
Public class OrderLinePk implements Serializable ...{
@ ManyToOne
@ JoinColumn (name = "foo", nullable = false)
Public Order order;
@ ManyToOne
@ JoinColumn (name = "bar", nullable = false)
Public Product product;
}
Join table
@ Entity
Public class Product ...{
@ Id
Public String name;
}
@ Entity
@ Table (name = "OrderTableFoobar ")
Public class Order ...{
@ Id
@ GeneratedValue
Public Integer id;
}