I have a class (Address) that is sometimes used as a component (for example, when storying a Company, which only has a main address) and other times as a composite-element (when storing a Person, which has multiple addresses).
Is there any way to keep the mapping definition of this element in only one file? The XML Entity include solution would require at least two (one for the component type and one for the composite element type).
For example I've got:
Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
[ <!ENTITY compositeAddress SYSTEM "classpath://mappings/compaddress.xml"> ]>
At the top of Person, and:
Code:
<composite-element class="esta.dataobjects.Address">
<property name="streetAddress" not-null="true" />
<property name="aptNumber" />
<property name="city" not-null="true" />
<many-to-one name="state" class="esta.dataobjects.State"
not-null="true" />
<property name="postalCode" not-null="true" />
</composite-element>
is in compaddress.xml. But since Company has only one address, it needs a <component> element, not a <composite-element> element (which is used in Person for an AddressType->Address map).
I don't want to store Address as a separate entity.
Any solutions?
PS: The error code when Hibernate can't find a file referenced in an ENTITY declaration on the classpath is "protocol not supported: classpath". Classy, no?