• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate StackOverflowError: bidirectional many-to-many

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two objects to persist; Account and Role. Account has a String username, a String password and a Set of Roles. Role has a String name, and a Set of Accounts. Hibernate creates a join table called accountroles to manage the Sets' many-to-many relationship. Everything works fine; Hibernate generates the correct SQL as far as I can tell. I inserted intermediate commits at each step just to make sure. On the last commit, I get a java.lang.StackOverflowError. I assume this has something to do with the bidirectional nature of the relationship. I must be getting an infinite loop of recursion or something. Any idea what I did wrong?

Thanks!

Hibernate version:
version 3.0.2 , 27.04.2005

Config file:



Mapping documents:
Account.hbm.xml


Role.hbm.xml



Code between sessionFactory.openSession() and session.close():



Schema-export.sql:



Full stack trace of any exception that occurs:
java.lang.StackOverflowError (that's it)


Name and version of the database you are using:
hsqldb_1_7_3_3


The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:
 
Brian Kuhn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I almost forgot to mention, the above code uses the same instance of HashSet for userRole and adminRole.

The following code gave me the exact same result:


I also tried out this project with MySQL 3.0.16 and had the same problem.

In case anyone wants to try this out, I've published the project at:
SimpleHibernateDemo.zip
 
Brian Kuhn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why my last reply shows up blank, but I also wanted to mention:

The above code uses the same instance of HashSet for userRole and adminRole. I also tried this:



but I got the same problem. I also tried out this project with MySQL 3.0.16. Same issue. In case anyone wants to try this out, I've published the project at:

http://java.briankuhn.com/SimpleHibernateDemo.zip
 
Brian Kuhn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why my last 2 replies show up blank, but I still want to mention:

The above code uses the same instance of HashSet for userRole and adminRole. I also tried this:



but I got the same problem. I also tried out this project with MySQL 3.0.16. Same issue. In case anyone wants to try this out, I've published the project at:

http://java.briankuhn.com/SimpleHibernateDemo.zip
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic