This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Problem in Mapping 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 "Problem in Mapping" Watch "Problem in Mapping" New topic

Problem in Mapping

Anupam Dee
Ranch Hand

Joined: Oct 18, 2010
Posts: 42

I have a Customer Class and an Address class as follows

Now I want to have two customers with the same address

//Now when i try to retrieve the Customer Object and iterate over the list i am not getting the address for the second customer. I am getting null there.

These are my HBM files



I am new to hibernate mapping.. please help me...

And i am a bit confused about the mapping strategies in hibernate..please suggest a good link too.
Bill Gorder

Joined: Mar 07, 2010
Posts: 1648

The way you have your objects defined you are expecting to a customer to have one address and that address to belong to exactly one Customer. But the way you are attempting to use it you are saying that one address can have many customers. With the way you have it defined you must define 2 Addresses with their own unique persistent ids even if they are both "ABCStreet"

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: Problem in Mapping
Similar Threads
org.hibernate.MappingException: table refers to an unmapped class
Foreign key must have same number of columns
Hibernate and MS Access?
One-to-One mapping problem
how hibernate maintain referential integrity