we have question about inheritance in PostgreSQL and mapping it as entities in JPA. Our database, and tables we want to map are:
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);
And we mapped them for entities using automatic tool in Netbeans 7.1.2. At first I thought it would be enough just to add
@Entity
@Table(name = "truefalseanswer", catalog = "jobfairdb", schema = "public")
@XmlRootElement
public class Truefalseanswer extends Answer implements Serializable {
private static final
so just extends, but it didn't work properly. What is the best approach to this? Thanks in advance.