开发者

identifying which jpa mapping between customer and currentPaymentMethod

I have written a Customer class which has two fields.A Set<Payment> payments and a selectedPayment .A customer can have many credit cards and can select one of them for current purchase.The various credit cards are modelled by the payments field.

@Entity
class Customer{
  ...
  @OneToMany( cascade=CascadeType.ALL,orphanRemoval=true)
  Set<Payment> payments;
  @OneToOne( cascade=CascadeType.ALL)
  Payment selectedPayment;

}

@Entity
class Payment{
   String creditCardNumber;
   String creditCardType;
   ...
}开发者_JAVA技巧

Are these the correct mappings? In the db table ,a customer can only be associated with a single Payment record through selectedPayment field.That is why I made it one-to-one.

Are there any pitfalls I haven't anticipated? Please advise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜