aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: ArryaList Collection associations are not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: ArryaList Collection associations are not working" Watch "Hibernate: ArryaList Collection associations are not working" New topic
Author

Hibernate: ArryaList Collection associations are not working

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
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


Cheers,<br />Sarav
gopal venu
Ranch Hand

Joined: Jan 06, 2006
Posts: 55
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

Joined: Jan 02, 2007
Posts: 47
It worked, Thank you buddy !!!
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Indeed, SQLGrammarException problems most often boil down to some type of mapping problem.

-Cameron McKenzie
Konda Golamaru
Ranch Hand

Joined: Dec 12, 2005
Posts: 36
Hi Saravanan,

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

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate: ArryaList Collection associations are not working