JPA OneToMany与抽象实体级联

时间:2017-03-01 14:15:26

标签: java hibernate jpa

我有一个抽象实体及其子类

@Entity
@Inheritance(JOIN)
public abstract class Foo { /* ... */ }

@Entity
public class Bar extends Foo { /* ... */ }

@Entity
public class Baz extends Foo { /* ... */ }

以及包含Foo s列表的类:

@Entity
public class Qux {

    @OneToMany(cascade = ALL)
    List<Foo> foos;

}

但是当我merge(qux)我得到

org.hibernate.PersistentObjectException: detached entity passed to persist: Foo

这很奇怪,因为我有cascade = ALL。所以我尝试将其更改为cascade = MERGE,错误更改为

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: Foo

如何使这种关系有效? (我正在使用Hibernate 5.2.7)

0 个答案:

没有答案
相关问题