This doesn't quite work.. OpenJPA 1.2.0 complains about Alias (an
Embeddable) not having an identity type:
org.apache.openjpa.persistence.ArgumentException: Cannot manipulate
identity of type "edu.cmu.hazen.domain.Alias": it's identity type is
unknown.
Andy Schlaikjer wrote:
I think may I've figured it out. It seems I can use a @JoinTable along
with @PersistentCollection to achieve something like this:
@Embeddable
public class Alias {
private String value;
private int frequency;
}
@Entity
public class Person {
@Id
private long id;
@PersistentCollection(elementEmbedded = true)
@ElementDependent
@JoinTable(
name = "PersonAlias",
joinColumns = @JoinColumn(name = "person_id"),
uniqueConstraints = @UniqueConstraint(
columnNames = { "person_id", "value" }
)
)
@OrderBy(value = "frequency desc, value asc")
private SortedSet<Alias> aliases;
}
CREATE TABLE Person (id BIGINT NOT NULL, PRIMARY KEY (id))
CREATE TABLE PersonAlias (person_id BIGINT NOT NULL, value VARCHAR(255)
NOT NULL, frequency INTEGER, UNIQUE UNQ_person_idvalue (person_id, value))
-Andy