我们对 PostgreSQL 中的继承以及将其映射为 JPA 中的实体有疑问。我们的数据库和我们要映射的表是:
CREATE TABLE Answer (
idAnswer SERIAL,
answerContent VARCHAR,
idQuestion INTEGER,
version INTEGER,
CONSTRAINT Answer_idAnswer_PK PRIMARY KEY (idAnswer),
CONSTRAINT Answer_idQuestion_FK FOREIGN KEY (idQuestion) REFERENCES Question(idQuestion)
);
CREATE TABLE MatchAnswer (
matchingAnswer VARCHAR NOT NULL,
version INTEGER,
CONSTRAINT MatchAnswer_idAnswer_PK PRIMARY KEY (idAnswer)
) INHERITS(Answer);
CREATE TABLE TrueFalseAnswer (
isTrue BOOLEAN NOT NULL,
version INTEGER,
CONSTRAINT TrueFalseAnswer_idAnswer_PK PRIMARY KEY (idAnswer)
) INHERITS(Answer);
我们使用 Netbeans 7.1.2 中的自动工具将它们映射为实体。起初我以为只要添加就足够了
@Entity
@Table(name = "truefalseanswer", catalog = "jobfairdb", schema = "public")
@XmlRootElement
public class Truefalseanswer extends Answer implements Serializable {
private static final
所以只是extends,但它不能正常工作。最好的方法是什么?提前致谢。