J2R wrote:
OK, I've moved on now to using a table per class hierarchy strategy and have run into another issue. Various different classes (Customer, Organisation, etc.) have multiple addresses, which I'm implementing as Lists of Address objects. They could all just use vanilla Address objects, but I'm not able to think of a way of doing this using Hibernate, at least not with the XDoclet tags. The reason is that in the 'many' class, in this case Address, you need to specify the 'one' class in the many-to-one tag. Thus:
/**
* @hibernate.many-to-one column="address_owner_id" class="testing.Customer"
*/
I clearly can't have the same Address class work with multiple different 'parent' classes. The approach I've taken is to have multiple subclasses of Address, namely CustomerAddress, OrganisationAddress, etc., which are effectively empty in that they do not provide any different behaviour from the superclass but are really just a place to put the different Hibernate XDoclet tags. So in the base Address class, I have a getAddressOwner() method, which I override in each subclass thus (from the CustomerAddress:
Well, you may have to think about directions of relation. Does address need to know that it belongs to certain entity? Do you like to navigate to this entity from adress?
You may have to create class hierarchy of "adressables" too...
Quote:
Now I have to say that this business of creating 'empty' classes merely as places to put Hibernate tags strikes me as not quite right - I would have hoped Hibernate would not need to be so intrusive. This leads me to suppose that there must be a much better way of doing this, and any ideas are most welcome!
Well, hibernate is intrusive - you still have to think about identites, collection types, (sometimes ) serializability, keys etc...