This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Resilient Oracle PL/SQL: Building Resilient Database Solutions for Continuous Operation and have Stephen Morris on-line!
See this thread for details.
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

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.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic