title: Hibernate @id composite
body: <p>I am modeling a database.<br>
  There is <code>TRIPLE</code> which contains three <code>CONCEPT</code>. So the primary key of the class <code>TRIPLE</code> is three <code>uri</code> all together.  (One concept could be in different <code>TRIPLE</code>).<br>
  Also <code>TRIPLE</code> is related with another class, <code>ANNOTATION</code>, and here is the question, how can <code>triple_id</code> be identified?? But first of all, if building this Id composite is correct.
  To model that:  </p>
  
  <p><strong>Concept.java</strong>  </p>
  
  <pre><code>@Entity
  @Table(name = "concept")
  public class Concept implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private String id;
      private List&lt;TripleDBModel&gt; triples;  
  @ManyToMany(
              cascade={CascadeType.ALL},  
              fetch=FetchType.LAZY, 
              mappedBy = "concepts"  
      )   
      public List&lt;TripleDBModel&gt; getTriples() {
          return triples;
      }
  
      public void setTriples(List&lt;TripleDBModel&gt; triples) {
          this.triples = triples;
      }
  </code></pre>
  
  <p><strong>ConceptPk.java</strong>  </p>
  
  <pre><code>@Embeddable
  public class ConceptPk implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private String uri;
  
      public ConceptPk(String uri, String label){
          this.uri = uri;
      }
  
      public ConceptPk(){
          super();
      }   
  
      @Id
      @Column(name = "uri", length = 100, unique = true, nullable = false)
      public String getUri() {
          return uri;
      }
      public void setUri(String uri) {
          this.uri = uri;
      }
  }
  </code></pre>
  
  <p><strong>Triple.java</strong>  </p>
  
  <pre><code>@Entity
  @IdClass(ConceptPk.class)
  @Table(name = "triple")
  public class TripleDBModel {
  
      protected List&lt;Annotation&gt; annotations;
      protected String conceptUriSubject;
      protected String conceptUriObject;
      protected String conceptUriPredicate;
  
  
  
      @ManyToMany(
              cascade={CascadeType.ALL},  
              fetch=FetchType.LAZY
      )   
      @JoinTable(name = "triple_has_concept", 
              joinColumns=@JoinColumn(name="uri"),
              inverseJoinColumns=@JoinColumn(name="triple_id")) //What shoul I write here???
      public List&lt;Annotation&gt; getAnnotations() {
          return annotations;
      }
      public void setAnnotations(List&lt;Annotation&gt; annotations) {
          this.annotations = annotations;
      }
      @Id public String getConceptUriSubject() {
          return conceptUriSubject;
      }
      public void setConceptUriSubject(String conceptUriSubject) {
          this.conceptUriSubject = conceptUriSubject;
      }
      @Id public String getConceptUriObject() {
          return conceptUriObject;
      }
      public void setConceptUriObject(String conceptUriObject) {
          this.conceptUriObject = conceptUriObject;
      }
      @Id public String getConceptUriPredicate() {
          return conceptUriPredicate;
      }
      public void setConceptUriPredicate(String conceptUriPredicate) {
          this.conceptUriPredicate = conceptUriPredicate;
      }
  }  
  </code></pre>
  
  <p>Thanks in advance!!</p>