我使用Spring数据jpa,我有两个具有继承关系的实体。
这是父母。
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name = "creditcardinfo")
@DiscriminatorColumn
public class CreditCardInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="credit_card_info_id")
private int creditCardInfoId;
这是孩子
@Entity
@DiscriminatorValue("tappay")
@Table(name = "tappaycardinfo")
@PrimaryKeyJoinColumn(name = "credit_card_info_id",referencedColumnName = "credit_card_info_id")
public class TappayCardInfo extends CreditCardInfo implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name = "card_token")
private String cardToken;
@Column(name = "card_key")
private String cardKey;
我将JpaRepository用于CRUD。这是我的存储库。
public interface TappayCardInfoDAO extends JpaRepository<TappayCardInfo, Integer>
当我保存我的TappayCardInfo时,我总是遇到异常。
@Inject private TappayCardInfoDAO tappayCardInfoDAO;
...
tappayCardInfoDAO.save(cardInfo);
此处有错误消息。
引起:java.lang.IllegalArgumentException:实体必须只有一个带id注释的属性,类名:base.model.TappayCardInfo