我有以下實體:JPA 2個Inheritance.TABLE_PER_CLASS與抽象的關係
@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{
...
}
}
的問題是,我得到下面的異常,當我試圖堅持一個業主與父元素:
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,它工作正常。任何想法爲什麼它試圖堅持父抽象類而不是孩子特定的?
非常感謝你,你真的拿到了尚方寶劍。 – domgom 2012-04-09 13:38:16