IllegalStateException with Hibernate 4 and ManyToOne cascading

后端 未结 9 2223
梦如初夏
梦如初夏 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:35

    Is your relationship between item and component unidirectional or bidirectional? If it's bidirectional make sure you don't have Cascade.MERGE calls going back up to Item.

    Basically, the newer version of Hibernate has a entity map that contains a list of all things that need to be merged based on the call to merge() it will call merge and then move onto the next one, but keep things in the map, it will throw the error you state above "An entity copy was already assigned to a different entity" when it encounters an item that has already been dealt with. We found in our app when we located these "upward" merges in the object graph ie. on bidirectional links, it fixed the merge call.

提交回复
热议问题