-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Sun Feb 19, 2012 7:39 pm 
Newbie

Joined: Sun Feb 19, 2012 7:23 pm
Posts: 5
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.. !!


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Sun Feb 19, 2012 11:39 pm 
Newbie

Joined: Thu Feb 02, 2012 11:28 pm
Posts: 13
Location: shenzhen china
Use @...on column or getter not both of them.

要不在列上使用annotation ,要不就在get方法上使用annotation,不要俩种都混着用。


BWT ,do you speak chinese?

Communication is so difficult,i can't spell some words.


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Mon Feb 20, 2012 5:10 am 
Newbie

Joined: Fri Feb 17, 2012 8:20 am
Posts: 18
Check this reference may be useful to you

Hibernate One To Many Annotation Example
Hibernate Many To One Annotation Example

Good luck


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Mon Feb 20, 2012 11:49 am 
Newbie

Joined: Sun Feb 19, 2012 7:23 pm
Posts: 5
Thanks strjames !! :-)


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Mon Feb 20, 2012 11:22 pm 
Newbie

Joined: Fri Feb 17, 2012 8:20 am
Posts: 18
You welcome friend :-)


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Tue Feb 21, 2012 1:03 am 
Newbie

Joined: Tue Feb 21, 2012 12:57 am
Posts: 5
That's also I need.Thank you.

_________________
nostale gold


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping ManyToOne-OneToMany
PostPosted: Tue Feb 21, 2012 2:47 pm 
Newbie

Joined: Sat Feb 18, 2012 11:31 am
Posts: 5
hello all, I have followed the sample in many to one relation, and when I save the elements in the 'many' side, I have this error:
a different object with the same identifier value was already associated with the session

My code is like:
tx = session.beginTransaction();
logclass LogClass = new logclass();

LogClass.setdFecha(dFecha);
LogClass.setsClase(sClase);
LogClass.setsMensaje(sMensaje);
LogClass.setiIdPrioridad(Integer.parseInt(sPrioridad));
LogClass.setsServidor(sServidor);
LogClass.setiIdCodigoError(Integer.parseInt(sCodigoError) );
LogClass.setsDetalle(sDetalle);

int id = (Integer)session.save(LogClass);

for( int i=0; i<vParametros.size() ; i ++ ){
Vector<String> vTemp= (Vector)vParametros.elementAt(i);
logparametrosclass logparam = new logparametrosclass();
logparam.setsParam((String)vTemp.elementAt(0));
logparam.setsValor((String)vTemp.elementAt(1));
logparam.setLog(LogClass);
session.save(logparam);

}

Could anyone give me a help?
thanks ins advance


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

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.