开发者

identifying which jpa mapping between customer and currentPaymentMethod

开发者 https://www.devze.com 2023-04-06 15:45 出处:网络
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 vari

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

精彩评论

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