This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: ArryaList Collection associations are not working

 
Saravanan Vijayappan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 POJOs: Menugroup, Catgroup. Menugroup has one-to-many replationship with Catgroup. Evenything works fine when I declared Catgroups as java.util.HashSet. I started getting the problem when I changed the collections type to java.util.List.

Getting the below exception:


Menugroup.java POJO is below:-




Catgroup.java POJO is below;-




Menugroup.hbm.xml is below:-




Catgroup.hbm.xml is below:-




This is my jave code snippet tries pull the data from DB:

List<?> menuGroups = dao.getSession().createCriteria(Menugroup.class).list;


Hibernate generates the below SQLs in the console:




I don't know, from where hibernate adds this column 'catgroups0_.idx' in the SQL since I never defined this column anywhere. The same thing works fine for Set Collections, but it is not working for java.util.List, this is really strange, I don't know whether I am really missing some thing or this a BUG in hibernate ?. Could any one please help me.

Thanks
Sarav
 
gopal venu
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it problem with your mapping xml file.

I THINK list element requires <list-index column="yourcolumnName"/> for indexing.Just add this and see I hope it will be working.
 
Saravanan Vijayappan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked, Thank you buddy !!!
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, SQLGrammarException problems most often boil down to some type of mapping problem.

-Cameron McKenzie
 
Konda Golamaru
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saravanan,

Could you please post the code you have used/developed to persist the said objects using one to many relation.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic