0

我在购物车和计划之间有一对多的关系。当我坚持购物车时,我想坚持购物车中的所有计划。我正在使用 Spring JPA 存储库。我已经尝试过单向和双向关联。在每种情况下,它都会失败并出现以下错误:

org.springframework.dao.DataIntegrityViolationException: ORA-01400: cannot insert NULL into ("SS"."SS_CART_PLANS"."CART_ID") ;SQL [不适用];约束[空];嵌套异常是 org.hibernate.exception.ConstraintViolationException: ORA-01400: cannot insert NULL into ("SS"."SS_CART_PLANS"."CART_ID")

映射如下:

@Entity
@Table(name = "SS_CART")
 public class Cart implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="SS_CART_PLANS_ID_GENERATOR", sequenceName="SS_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE,                       generator="SS_CART_PLANS_ID_GENERATOR")
    private long id;

@OneToMany(cascade=CascadeType.ALL,mappedBy="cart")
private Set<CartPlan> cartPlans;

// uni-directional many-to-one association to SsUser
@ManyToOne(cascade= {CascadeType.ALL })
@JoinColumn(name = "USER_ID")
private User user;

public Cart() {
}

public long getId() {
    return this.id;
}

public void setId(long id) {
    this.id = id;
}

public Set<CartPlan> getCartPlans() {
    return this.cartPlans;
}

public void setCartPlans(Set<CartPlan> cartPlans) {
    this.cartPlans = cartPlans;
}

/**
 * @return the user
 */
public User getUser() {
    return user;
}

/**
 * @param user the user to set
 */
public void setUser(User user) {
    this.user = user;
}

}




    @Entity
@Table(name="SS_CART_PLANS")
public class CartPlan implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @SequenceGenerator(name="SS_CART_PLANS_ID_GENERATOR", sequenceName="SS_SEQ")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SS_CART_PLANS_ID_GENERATOR")
    private long id;

    @Temporal(TemporalType.DATE)
    @Column(name="EFFECTIVE_DATE")
    private Date effectiveDate;

    @Column(name="ISSUER_CODE")
    private String issuerCode;

    @Column(name="PLAN_CODE")
    private String planCode;

    //bi-directional many-to-one association to SsCartPlan
    @OneToMany(cascade=CascadeType.ALL)
    @JoinColumn(name="PARENT_PLAN_ID")
    private Set<CartPlan> cartPlans;

    @ManyToOne
    @JoinColumn(name="CART_ID")
    @ForeignKey(name="SS_CART_PLANS_CART_FK")
    private Cart cart;

    //bi-directional one-to-one association to SsSearchCriteria
    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="CRITERIA_ID")
    private SearchCriteria searchCriteria;

    public CartPlan() {
    }

    public long getId() {
        return this.id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Date getEffectiveDate() {
        return this.effectiveDate;
    }

    public void setEffectiveDate(Date effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    public String getIssuerCode() {
        return this.issuerCode;
    }

    public void setIssuerCode(String issuerCode) {
        this.issuerCode = issuerCode;
    }

    public String getPlanCode() {
        return this.planCode;
    }

    public void setPlanCode(String planCode) {
        this.planCode = planCode;
    }

    /**
     * @return the cartPlans
     */
    public Set<CartPlan> getCartPlans() {
        return cartPlans;
    }

    /**
     * @param cartPlans the cartPlans to set
     */
    public void setCartPlans(Set<CartPlan> cartPlans) {
        this.cartPlans = cartPlans;
    }

    /**
     * @return the searchCriteria
     */
    public SearchCriteria getSearchCriteria() {
        return searchCriteria;
    }

    /**
     * @param searchCriteria the searchCriteria to set
     */
    public void setSearchCriteria(SearchCriteria searchCriteria) {
        this.searchCriteria = searchCriteria;
    }

    /**
     * @return the cart
     */
    public Cart getCart() {
        return cart;
    }

    /**
     * @param cart the cart to set
     */
    public void setCart(Cart cart) {
        this.cart = cart;
    }

   }
4

1 回答 1

1

我想你cardCardPlan坚持之前忘记了。

于 2013-03-12T06:13:36.070 回答