Hi!
I have two tables:
Code:
------------- -------------
| Person | | Addresses |
------------- -------------
| ID | | Person_ID |
| FirstName | | Street |
| LastName | | City |
| BirthDate | | Zip |
------------- -------------
where ID in table person is the primary key and referenced in table Addresses as a foreign key in the field Person_ID. When I now reverse engineer this schema with the Hibernate tools in Eclipse, a composite ID will be created for all the columns in the table Addresses. I then have three classes:
Code:
Person
AddressesID
Addresses
where Addresses is mainly a wrapper for the AddressesID class and all the fields are contained in the AddressesID class. When I want to create a new Address, I have to instantiate a new AddressesID class and set all fields (street, city, zip) in this class. Then I have to use this class and pass it in the constructor of the Addresses class. Again when retrieving values, I have to do something like this:
Code:
person.getAddresses().iterator().next().getAddressesID().getStreet();
I have this ugly indirection over AddressesID. I want something like this:
Code:
person.getAddresses().iterator().next().getStreet();
Now my question: is there a way to directly map the table addresses to a class Addresses without introducing this composite ID? I have seen that any mapping file must contain an id|composite-id element. How can I reference the foreign key Person_ID in this mapping, without having to introduce a new key?
thanks