openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Schlaikjer <ha...@cs.cmu.edu>
Subject Re: how to specify index / unique constraint on multiple columns of a container table?
Date Wed, 15 Oct 2008 18:07:46 GMT
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


Mime
View raw message