-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to work with interfaces and embedded classes ?
PostPosted: Thu Mar 06, 2008 8:54 am 
Newbie

Joined: Thu Mar 06, 2008 8:34 am
Posts: 1
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can do that by using the hibernate specific @Target annotation

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.