Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2.6
Hello everybody,
I am trying to map an interface as embedded attribute, but I do not figure out how.
All the entities of my application are implemented as interface/implementation pairs. An entity only knows the interface of the other entities and does not see their implementation details. How is it possible to map en embedded class to an attribute defined as an interface ?
Example :
the main class is an address. It has a country attribute that is embedded in the address table.
The contry attribute is of type Country and its implementation is called CountryImpl. The embeddable element in my mapping file (I work with mapping files, not with annotations) is defined for CountryImpl, I cannot give the interface since it cannot be implemented.
But, here is the problem, if I define the country attribute of the address as Country, Hibernate wont load the data since the embeddable is of type CountryImpl. It works only if the type of the country attribute is CountryImpl, but that goes against my developement rules and causes the implementation details to be visible for other classes.
Is there a work around to this problem ?
Thank you
Stefano
My mapping file and the AddressImpl class:
<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl" access="FIELD" metadata-complete="true">
<discriminator-value>P</discriminator-value>
<attributes>
<basic name="firstName">
<column name="FIRST_NAME"/>
</basic>
<basic name="lastName">
<column name="LAST_NAME"/>
</basic>
<basic name="street"></basic>
<basic name="zip"></basic>
<basic name="city"></basic>
<embedded name="country" >
<attribute-override name="externalApplication">
<column name="COUNTRY_APP_DEF"/>
</attribute-override>
<attribute-override name="externalId">
<column name="COUNTRY_ID"/>
</attribute-override>
</embedded>
</attributes>
</entity>
<embeddable class="ch.admin.bit.fw2.demo.bm.CountryImpl" access="FIELD" metadata-complete="true">
<attributes>
<transient name="code"/>
<transient name="name"/>
</attributes>
</embeddable>
public class PostalAddressImpl extends AbstractAddressImpl implements PostalAddress {
private String firstName;
private String lastName;
private String street;
private Country country;
private String zip;
private String city;
etc.