Hello,
I have a complicated mapping problem:
Consider the following db schema:
I need to map this to the following beans, and unfortunately I can't change nor the bean structure neither the db schema.
Code:
public class EOActivity extends BaseBean implements Serializable {
private String activityName;
private Set<EOUser> eoUser;
...
public class EOUser extends BaseBean implements Serializable {
private String eoUserId;
private EOUserAddress eoUserAddress;
...
public class EOUserAddress extends BaseBean implements Serializable {
private Recipient recipient;
private String email;
private String telephone;
private String fax;
private String addressType;
private PostalAddressInfo postalAddress;
private FtpAccount ftpAccount;
private String organisationName;
....
So far I have tried the following mappings:
Code:
<class name="EOActivity" table="cdb_eo_activities">
<id name="activityName" column="activity"/>
<set name="eoUser" lazy="false" fetch="join" cascade="all">
<key foreign-key="none">
<column name="customerId"/>
<column name="activity"/>
</key>
<one-to-many class="EOUser"/>
</set>
</class>
<class name="EOUser" table="cdb_eo_activity_address">
<id name="eoUserId" column="eoUserId"/>
<set name="eOUserAddress" lazy="false" fetch="join" cascade="all">
<key foreign-key="none">
<column name="customerId"/>
<column name="activity"/>
<column name="eoUserId"/>
</key>
<one-to-many class="EOUserAddress"/>
</set>
</class>
<class name="EOUserAddress" table="cdb_eo_activity_address">
<id name="addressType"/>
<component name="recipient">
<property name="title"/>
<property name="firstName"/>
<property name="surName"/>
</component>
<property name="telephone"/>
<property name="fax"/>
<property name="email"/>
<property name="organisationName"/>
<many-to-one name="ftpAccount" class="FtpAccount" lazy="false" fetch="join"/> <!-- no cascade -->
<many-to-one name="postalAddress" class="PostalAddressInfo" lazy="false" fetch="join"/> <!-- no cascade -->
</class>
This doesn't work: "collection foreign key mapping has wrong number of columns", due to the non-declaration of the composite primary key in EOUser (which I can't declare there, because I can only have 'eoUserId' in the EOUser bean). I know the db schema is sh*t (no direct PK's, only foreign keys which form a PK), but I'd like to know if it is possible to map this with Hibernate.
Thanks in advance.
Joris