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

Reply via email to