IllegalStateException with Hibernate 4 and ManyToOne cascading

后端 未结 9 2151
梦如初夏
梦如初夏 2020-12-01 16:06

I\'ve got those two classes

MyItem Object:

@Entity
public class MyItem implements Serializable {

    @Id
    private Integer id;
    @ManyToOne(casc         


        
9条回答
  •  离开以前
    2020-12-01 16:30

    If name is the Id why are you creating two objects with the same id?? you can use the c1 object in all the code.

    If that's only an example and you create the c2 object in another part of the code, then you shouldn't create a new object but load it from database:

    c2 = itemDao.find("comp", Component.class); //or something like this AFTER the c1 has been persisted
    

提交回复
热议问题