wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Simple One to Many not working in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Simple One to Many not working in Hibernate" Watch "Simple One to Many not working in Hibernate" New topic

Simple One to Many not working in Hibernate

Darren Carter
Ranch Hand

Joined: Jul 08, 2010
Posts: 30
Hi Everyone,

I really hope someone could help as I been struggling with an issue with hibernate and a spring mvc app. I must be doing something silly and was hoping someone could help.

I have the following relationships

1) SiteMenu has many MenuSection
2) SiteMenu has one Site
2) MenuSection has Many Products

I simply trying to retrieve a SiteMenu object which contains all the MenuSecions and associated Products. However when I add the products to my hibernate mapping (MenuSection.hbm), I receive duplicate MenuSection objects in my query. Removing the products association returns the correct number of MenuSections.

Here are the Hibernate Mappings

Here is my Criteria query

Why is it if I introduce products it duplicates the records returned? Can some please help as I am not sure what to do?

Best Regards

Consider Paul's rocket mass heater.
subject: Simple One to Many not working in Hibernate
Similar Threads
Foreig key must have same number of columns as the referenced primary key
java.lang.OutOfMemoryError: Java heap space
A different object with the same identifier?
Not-null property references a null or transient value
Querying tables with a one-to-many foreign key relationship