I'm evaluating the possibility of using hibernate with our legacy database schema and when writing some test code I stumbled into this:
Thre is an ADDRESS table in the database holding different types of addresses (email and postal). Each type is identified by a different ADDRESS_TYPE_ID. Now I want to map a set of Address objects to a Person corresponding to all the rows in ADDRESS with matching PERSON_ID and ADDRESS_TYPE_ID = 1.
For reading it works great with <set ... where="ADDRESS_TYPE_ID = 1">, but inserting is another story. How do I tell hibernate to set ADDRESS_TYPE_ID to 1 for all persisted Address instances?
The idea I have come up with is adding a custom UserType for some simple value in the Address mapping that also inserts a value for ADDRESS_TYPE_ID, but that solution seems kind of ugly.
|