在Hibernate中更新集合实体问题

时间:2015-04-30 13:28:40

标签: java hibernate

我有实体Car和User

    @Entity
    public class Car{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    long id;
    String name;
    ........

    @Entity
    public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    long id;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    List<Car> carList;
    .......

我成功地能够保存实体用户,但是当尝试用新车更新用户(即添加新车)时

   user.addCars(car);

   updateUser(user);

它给予例外

     Hibernate Exception Could not execute JDBC batch update

0 个答案:

没有答案