Join inheritance type and composite primary keys
Hi,
I'm having trouble in defining a joined inheritance relationship with composite keys. I'm using glassfish v2 b25 and PostgreSQL 8.1.
My first unsuccessfully attempt was:
---------------
@Entity
@Inheritance(strategy = InheritanceType.JOINED )
public class Parent {
@Id
@Column(name="ID")
protected long id;
@Id
@Column(name="NAME", nullable=false)
protected String name;
public Parent() {
}
}
@Entity
public class Child extends Parent {
@Lob
private String summaryText;
public Child() {
}
}
-----
Deploy fails with the following error:
"Exception Description: An incomplete @PrimaryKeyJoinColumns was specified on the annotated element [class test.Child]. When specifying @PrimaryKeyJoinColumns for an entity that has a composite primary key, a @PrimaryKeyJoinColumn must be specified for each primary key join column using the @PrimaryKeyJoinColumns. Both the name and the referenceColumnName elements must be specified in each such @PrimaryKeyJoinColumn."
Then I change the Child class and added the @PrimaryKeyJoinColumns annotation:
-----
@Entity
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="ID", referencedColumnName="ID"),
@PrimaryKeyJoinColumn(name="LOCALE", referencedColumnName="LOCALE")
})
public class Child extends Parent {
@Lob
private String summaryText;
public Child() {
}
}
But has expected deploy fails with the following error:
JDO76609: Got SQLException executing statement "ALTER TABLE CHILD ADD CONSTRAINT FK_CHILD_LOCALE FOREIGN KEY (LOCALE, ID) REFERENCES PARENT (LOCALE, ID)": org.postgresql.util.PSQLException: ERROR: there is no unique constraint matching given keys for referenced table "parent"
Any idea how to solve the problem?
Thanx
Vitor Carreira