Home > Software design >  onetoonemapping in jpa with foerign key present in child table
onetoonemapping in jpa with foerign key present in child table

Time:11-14

enter image description here

enter image description here

i want to have a one to one relationship in jpa,where i will save parent price and child price should automatically get saved.my ID in parent price is generated by sequence.can somebody help me with the entity class.i don't have any foreign key refence in parent table(parent_price)

CodePudding user response:

You have to use @JoinColumn to tell JPA that it should us the FK on the CHILD_PRICING table.

For example

@OneToOne
@JoinColumn(name="ID")
private ChildPricing childPricing;

CodePudding user response:

Try with PrimaryKeyJoinColumn :

@Entity
public class ChildPricing {
  @OneToOne
  @PrimaryKeyJoinColumn
  private ParentPrice parentPrice;

  private String priceName;
}
  • Related