-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Primary key composed by 3 instances from the same field
PostPosted: Wed Apr 13, 2011 4:57 am 
Newbie

Joined: Wed Dec 29, 2010 8:58 am
Posts: 10
Hello, although I made a little research on this, and I found a lot of threats opened in Internet, I couldn't solve my problem. I atache my code:

Triple.java the primary key is made by 3 uris from three different concepts, but it is the same column (is it a problem?)

Code:
@Entity
            @IdClass(ConceptPk.class)
            @Table(name = "triple")
            public class TripleDBModel {
           
               protected List<Annotation> annotations;
               public String conceptUriSubject;
               public String conceptUriObject;
               public String conceptUriPredicate;
                public String id;
           
               
               
               @ManyToMany(
                       cascade={CascadeType.ALL},   
                       fetch=FetchType.LAZY
               )   
                @JoinTable(name = "triple_has_annotation",
                      joinColumns=@JoinColumn(name="annotation_id"),
                        inverseJoinColumns={@JoinColumn(name="uri_concept_subject", referencedColumnName="triple_id"), @JoinColumn(name="uri_concept_object", referencedColumnName="triple_id"), @JoinColumn(name="uri_concept_predicate", referencedColumnName="triple_id")
            })//EDIT
               public List<Annotation> getAnnotations() {
                  return annotations;
               }
               public void setAnnotations(List<Annotation> annotations) {
                  this.annotations = annotations;
               }
               @Id
               @Column(name = "uri_concept_subject", length = 100)
               public String getConceptUriSubject() {
                  return conceptUriSubject;
               }
               public void setConceptUriSubject(String conceptUriSubject) {
                  this.conceptUriSubject = conceptUriSubject;
               }
               @Id
               @Column(name = "uri_concept_object", length = 100)
               public String getConceptUriObject() {
                  return conceptUriObject;
               }
               public void setConceptUriObject(String conceptUriObject) {
                  this.conceptUriObject = conceptUriObject;
               }
               @Id
               @Column(name = "uri_concept_predicate", length = 100)
               public String getConceptUriPredicate() {
                  return conceptUriPredicate;
               }
               public void setConceptUriPredicate(String conceptUriPredicate) {
                  this.conceptUriPredicate = conceptUriPredicate;
               }
   
     @Id
           @Column(name = "triple_id", unique = true, nullable = false)
           public String getId() {
              return id;
           }
           public void setId(String id) {
              this.id = id;
           }
        } 


ConceptPk.java

Code:
@Embeddable
        public class ConceptPk implements java.io.Serializable {
       
           private static final long serialVersionUID = 1L;
           public String conceptUriSubject;
           public String conceptUriObject;
           public String conceptUriPredicate;
           
           @Id
           @Column(name = "uri", length = 100, unique = true, nullable = false)
           public String getConceptUriSubject() {
              return conceptUriSubject;
           }
           public void setConceptUriSubject(String conceptUriSubject) {
              this.conceptUriSubject = conceptUriSubject;
           }
           
           @Id
           @Column(name = "uri", length = 100, unique = true, nullable = false)
           public String getConceptUriObject() {
              return conceptUriObject;
           }
           public void setConceptUriObject(String conceptUriObject) {
              this.conceptUriObject = conceptUriObject;
           }
           
           @Id
           @Column(name = "uri", length = 100, unique = true, nullable = false)
           public String getConceptUriPredicate() {
              return conceptUriPredicate;
           }
           public void setConceptUriPredicate(String conceptUriPredicate) {
              this.conceptUriPredicate = conceptUriPredicate;
           }



Annotation.java

Code:
@Entity
        @Table(name = "annotations")
        public class Annotation {
       
           private Integer id;
           private List<TripleDBModel> triples; 
       
        @Id
           @GeneratedValue(strategy = GenerationType.IDENTITY)
           @Column(name = "annotation_id", unique = true, nullable = false)
           public Integer getId() {
              return id;
           }
       
           public void setId(Integer id) {
              this.id = id;
           }
            
        @ManyToMany(
                   cascade={CascadeType.ALL},
                   mappedBy = "annotations", //EDIT
                   fetch=FetchType.LAZY
           )   
           public List<TripleDBModel> getTriples() {
              return triples;
           }
       
           public void setTriples(List<TripleDBModel> triples) {
              this.triples = triples;
           }



But I am getting this error:

Caused by: org.hibernate.AnnotationException: A Foreign key refering TripleDBModel from Annotation has the wrong number of column. should be 3


What am I doing wrong?? Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.