Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Many-to-many bidirectional mapping. Stack Overflow

 
varun deshpande
Greenhorn
Posts: 1
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying a Many-to-many bidirectional mapping.

my code is



Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tr = null;
ArrayList<StudentInfo> slist = new ArrayList<StudentInfo>();
ArrayList< CourseInfo>course = new ArrayList<CourseInfo>();
try{
tr = session.beginTransaction();
slist = (ArrayList<StudentInfo>)session.createQuery("from student.StudentInfo where sid = " +sid).list();
if(slist == null)
{
System.out.println("slist = null");
return;
}
System.out.println("slist not null");
System.out.println(slist);
StudentInfo stud = slist.get(0);
System.out.println(stud);
for(int i = 0; i < co.length; i++)
{
int cid = Integer.parseInt(co[i]);
course = (ArrayList<CourseInfo>)session.createQuery("from course.CourseInfo where cid = " +cid).list();
CourseInfo cou = course.get(0);
stud.getCourse().add(cou);
}



This code works fine that entry is made in database but while printing course it gives Stack over flow error

1) i am printing student info with course where course is set it gives error when it encounter getCourse() method






 
Javid Jamae
Author
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"co" that is in your for loop is not defined in your code. Please show us all your code and put it in a code block so we can read it easier.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic