-->
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/ Foreign Key
PostPosted: Tue Oct 09, 2007 10:53 pm 
Newbie

Joined: Thu Aug 23, 2007 9:52 pm
Posts: 9
I am getting the exception org.hibernate.AnnotationException: A Foreign key refering Teacher from Student has the wrong number of column. should be 2

The code is as follows. Can some one please help me with this code , what am I doing wrong ? :-( I have eliminated get/set from all classes

DB Schema:

Teacher(id,name)
Student(id , teacher_id, teacher_name)

Code:
@Entity
@Table(name="Teacher")

public class Teacher implements Serializable {

    @EmbeddedId
    private PK pk = new PK();

    @OneToMany(cascade = {CascadeType.ALL})
    @JoinColumn(name="teacher_id")   
    private List<Student> student;

    public List<Student> getStudent() {
        return student;
    }

    public void setStudent(List<Student> student) {
        this.student = student;
    }   
}


/////////////////////
@Entity
@Table(name="Student")

public class Student implements Serializable {

    @Id
    @Column(name="id")   
    private int id;

    @ManyToOne
    @JoinColumns ( {@JoinColumn(nullable=false, name="id"),
                    @JoinColumn(nullable=false, name="name")})
    private Teacher teacher;
}

///////////////////////////
@Embeddable
public class PK implements Serializable
{
      private int id;
      private String name;
}



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.