如何使用两个@manytomany属性来持久保存Jpa实体

时间:2012-05-28 16:05:48

标签: java java-ee persistence jpa-2.0

我有一个带有两个@manytomany anotated属性的实体。这里的问题是,其中一个属性是持久的而另一个属性不是。可能是什么问题呢。该实体如下。

@Entity("payment")
 public class PaymentData implements Serializable
{
    private Long pk;

    private Collection<PaymentItemData> paymentItem;
    /**
     *  minorPaymentItem
     *
     */
    private Collection<MinorPayItemData> minorPaymentItem;

@LazyCollection(LazyCollectionOption.FALSE)
    @ManyToMany
    @JoinTable(name = "payitem_m_assig",
    joinColumns =
    @JoinColumn(name = "pay_item_id", nullable = false),
    inverseJoinColumns =
    @JoinColumn(name = "minor_pay_item_id", nullable = false))
    public Collection<MinorPayItemData> getMinorPaymentItem()
    {
        return minorPaymentItem;
    }

    /**
     * @param minorPaymentItem the minorPaymentItem to set
     */
    public void setMinorPaymentItem(final Collection<MinorPayItemData> value)
    {
        this.minorPaymentItem = value;
    }



 @LazyCollection(LazyCollectionOption.FALSE)
    @ManyToMany
    @JoinTable(name = "payitem_assigned",
    joinColumns =
    @JoinColumn(name = "pay_item_id", nullable = false),
    inverseJoinColumns =
    @JoinColumn(name = "new_pay_item_id", nullable = false))
    public Collection<PaymentItemData> getPaymentItem()
    {
        return paymentItem;
    }

    /**
     * Set the property paymentItem
     *
     * @param value -paymentItem
     *
     */
    public void setPaymentItem(final Collection<PaymentItemData> value)
    {
        this.paymentItem = value;
    }    

}

 @Entity("minor")
    public class MinorPayItemData implements Serializable
    {

    }

 @Entity("major")
    public class PaymentItemData extends MinorPayItemData
    {

    }

MinorPayItemData和PaymentItemData保存在同一个数据库中。它们由一个鉴别栏分开。

仅保留paymentItem属性。我做错了什么。

0 个答案:

没有答案