Hi,
I'm wondering if there is a more elegant solution to my current problem:
I have two classes: User and Address.
A user has more than one address associated with it but only one current address.
Ideally I would like the user bean to contain only the latest address such that user.getAddress() returns the current address object for this user.
One possible solution would be to load all historic addresses for this user as a list ordered by date created and return only the latest address in the getAddress method.
Another solution would be to have a one-to-one mapping between user and address and split the address tables into to two: current_address and historic_addresses
Is there a more hibernate way of doing this? Such that I have a one-to-one mapping between user and latest address enforced by some kind of custom load SQL or configuration?
I imagine my hbm.xml files would look something like this:
Code:
<class name="User" table="user">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="firstName"/>
<property name="LastName"/>
<!-- Solution would go here -->
</class>
<class="name"Address" table="address">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="street"/>
<property name="town"/>
<property name="createdDate"/>
<many-to-one name="user" column="user_id"/>
</class>
Thanks in Advance,
puow