Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 1
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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






 
Author
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic