Hi All,
I am new to hibernate,
using hibernate 3.0 in oracle.
I have three tables company, company_address and address table.
Company and Address are related thru company_address table.
the company_address table has three fields
1.address_id 2.address_type_id -->primary keys
3.company_id.
address_id from address table, company_id from company table.
I have three objects (company,companyaddress,address).
company and address need to be populated before populating company_address table.
I created this mapping, please verify this is correct.
<hibernate-mapping>
<!-- This mapping inserts, updates, deletes rows into COMPANY and
table -->
<class name="com.myproj.wsobjects.Company" table="COMPANY">
<id name="id" unsaved-value="null"
column="ID">
<generator class="sequence">
<param name="sequence">SEQ_COMPANY</param>
</generator>
</id>
<property name="name" column="NAME" />
<property name="statusId" column="COMPANY_STATUS_ID" />
<property name="countryCode" column="COUNTRY_CODE" />
<property name="industry_id" column="INDUSTRY_ID" />
<property name="revenue_group_id" column="REVENUE_GROUP_ID" />
<property name="company_size_id" column="COMPANY_SIZE_ID" />
<property name="company_type_id" column="COMPANY_TYPE_ID" />
</class>
<!-- added new company_address table mapping -->
<class name="com.myproj.wsobjects.CompanyAddress" table="COMPANY_ADDRESS">
<composite-id>
<key-property name="address_id" column="ADDRESS_ID" />
<key-property name="address_type_id" column="ADDRESS_TYPE_ID" />
</composite-id>
<many-to-one name="company" column="COMPANY_ID" not-null="true"></many-to-one>
<many-to-one name="address" column="ADDRESS_ID" not-null="true"></many-to-one>
</class>
<!-- added new address table mapping -->
<class name="com.myproj.wsobjects.Address" table="ADDRESS">
<id name="id" unsaved-value="null"
column="ID">
<generator class="sequence">
<param name="sequence">SEQ_ADDRESS</param>
</generator>
</id>
<property name="address1" column="ADDRESS1" type="java.lang.String" />
<property name="address2" column="ADDRESS2" type="java.lang.String" />
<property name="city" column="CITY" type="java.lang.String" />
<property name="postalCode" column="POSTAL_CODE" type="java.lang.String" />
<property name="state_prov_id" column="STATE_PROV_ID" />
</class>
</hibernate-mapping>
I am using the company object everywhere (for add, delete,save etc).
Where will i add the getters and setters for company_address and address table.
I want to use a single object which will populate all these fields in my code.
How to achieve this.
Thanks a lot for all your inputs.
|