我有以下实体:
@Entity
public class Owner{
@Id
@Column(name = "OWNER_ID")
@OneToMany()
@JoinColumn(name = "OWNER_ID")
private Set<Parent> parents;
...
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Parent{
@Id
@Column(name = "PARENT_ID")
...
}
@Entity
public class ChildA extends Parent{
...
}
@Entity
public class ChildB extends Parent{
...
}
}
问题是当我尝试使用父元素持久化 Owner 时出现以下异常:
org.springframework.dao.InvalidDataAccessResourceUsageException:无法插入集合:[sample.Owner.parents#1];SQL [更新父集OWNER_ID=? 其中 PARENT_ID=?]; org.springframework.dao.InvalidDataAccessResourceUsageException:无法插入集合:[sample.Owner.parents#1];SQL [更新父集OWNER_ID=? 其中 PARENT_ID=?]; 嵌套异常是 org.hibernate.exception.SQLGrammarException:无法插入集合:[sample.Owner.parents#1] 嵌套异常是 org.hibernate.exception.SQLGrammarException:无法插入集合:[sample.Owner.parents#1]
如果我将 InheritanceType 更改为 JOINED 它工作正常。关于为什么它试图坚持父抽象类而不是子特定类的任何想法?