Hi,
I'm having trouble getting Hibernate to process my mappings. I have a 2-table schema with a CUSTOMER_ACCOUNTS table keyed on a composite PK (Acount_Number, Site_ID). This is referenced by a CUSTOMER_TELEPHONES table, using the . The DDL is appended to the end of this email. My Customer mapping file looks like this:
<class name="uk.co.blueyonder.dialup.dao.Customer" table="CMS_ACCOUNTS">
<composite-id name="id" class="uk.co.blueyonder.dialup.dao.CustomerCompositeId">
<key-property name="accountNumber" type="integer" column="Account_Number" />
<key-property name="siteID" type="integer" column="Site_ID" />
</composite-id>
<property name="password" column="Cms_Password" type="string"
<!-- More properties here .... -->
<set name="telephoneAccounts" table="CMS_TELEPHONES" cascade="all">
<key>
<column name="Account_Number" />
<column name="Site_ID" />
</key>
<one-to-many class="uk.co.blueyonder.dialup.dao.TelephoneAccount"/>
</set>
</class>
- So I would like to have a Set of TelephoneAccounts associated with each
Customer object, and pull them back with Customer.getTelephoneAccounts(). My TelephoneAccount.hbm.xml is shown here:
<class name="uk.co.blueyonder.dialup.dao.TelephoneAccount" table="CMS_TELEPHONES">
<composite-id name="id" class="uk.co.blueyonder.dialup.dao.CustomerCompositeId">
<key-property name="accountNumber" type="integer" column="Account_Number" />
<key-property name="siteID" type="integer" column="Site_ID" />
</composite-id>
<property name="unformattedTelephoneNumber" column="Unformatted_Telephone_Number" type="string" />
<property name="formattedTelephoneNumber" column="Formatted_Telephone_Number" type="string" />
</class>
Hibernate attempts to map these files, but it fails whenever it encounters the <set> declaration. No errors that I can see, it just seems to stop. (I'm looking at the Tomcat logs, BTW). If I take the <set> declaration out, it maps OK, but that's not what I want. Bearing in mind that the (Account_Number + Site_ID) combination will be unique in the CUSTOMER_ACCOUNTS table, but not in the CUSTOMER_TELEPHONES table (i.e one customer may have many telephone accounts), what am I doing incorrectly in the mapping? I'm sure I'm missing something painfully obvious - the <composite-id> declaration in the TelephoneAccount mapping, perhaps?
Here is the DDL:
create table CMS_ACCOUNTS (
Site_ID number(3) not null,
Account_Number number(9) not null,
Cms_Password varchar2(20),
Service_Type varchar2(1),
Last_Bill_Value number(9,2),
Last_bill_Date date,
Previous_Bill_Value number(9,2),
Previous_Bill_Date date,
Customer_Name varchar2(32),
Address_Line_1 varchar2(32),
Address_Line_2 varchar2(32),
Address_Line_3 varchar2(32),
Address_Line_4 varchar2(32),
Postcode varchar2(10)
);
create table CMS_TELEPHONES (
Site_ID number(3) not null,
Account_Number number(9) not null,
Unformatted_Telephone_Number varchar2(13),
Formatted_Telephone_Number varchar2(13)
);
alter table CMS_ACCOUNTS add constraint pk_cms_accounts primary key(Account_Number, Site_ID);
create index cms_telephony_idx on CMS_TELEPHONES(Account_Number, Site_ID);
Any help would be much appreciated
Cheers,
Rory
|