Hello Frnds,
I was trying execute simple mappling between Student and College.
Quote:
A College can have many Students
.
Every time I am getting the same error ~
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)]CODE Perspective:
I made two classes STUDENT:
@Entity
public class Student {
private String StudentName;
@Id
@GeneratedValue(strategy=IDENTITY)
private String StudentId;
private College college;
public String getStudentName() {
return StudentName;
}
public void setStudentName(String studentName) {
StudentName = studentName;
}
public String getStudentId() {
return StudentId;
}
public void setStudentId(String studentId) {
StudentId = studentId;
}
@ManyToOne
@JoinColumn(name = "college_id")
public College getCollege() {
return college;
}
public void setCollege(College college) {
this.college = college;
}
}
AND COLLEGE:
@Entity
public class College {
@Id
@GeneratedValue(strategy=IDENTITY)
private String CollegeId;
private String CollegeName;
private List<Student> students;
public String getCollegeId() {
return CollegeId;
}
public void setCollegeId(String collegeId) {
CollegeId = collegeId;
}
public String getCollegeName() {
return CollegeName;
}
public void setCollegeName(String collegeName) {
CollegeName = collegeName;
}
@OneToMany(targetEntity = Student.class, mappedBy = "college", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
}
----------
MAIN class :
sessionFactory = new Configuration().configure()
.buildSessionFactory();
transaction = session.beginTransaction();
College college = new College();
college.setCollegeName("NewYork College");
Student s1 = new Student();
s1.setStudentName("Vikram");
s1.setCollege(college);
Student s2 = new Student();
s2.setStudentName("Sita");
s2.setCollege(college);
session.save(college);
session.save(s1);
session.save(s2);
transaction.commit();
session.close();
-----------------------------
I am using Hibernate
hibernate-3.6.2
hibernate-jpa-2.0-api-1.0.0.Final
hibernate-validator-4.1.0.Final
MYSQL
----------------
Please suggest where I could be wrong..!! I need your help urgently.. Plz.. !!