0

I"m new to Hibernate. I have 3 tables: Companies, Profiles and Sites. The relation is - one company has many Profiles and Sites (one-to-many).

<hibernate-mapping>

<class name="com.bla.dataobject.CompanyData" table="companies">
 <id name="companyId" column="company_id">
  <generator class="increment"/>
 </id>
 <property name="name" column="company_name" type="java.lang.String"/>
 <property name="description" column="company_information" type="java.lang.String"/>

 <set name="sites" table="company_sites" inverse="true" cascade="all-delete-orphan" lazy="false">
    <key column="company_id" />
    <one-to-many class="com.bla.dataobject.CompanySiteData"/>
 </set>

 <set name="profiles" table="company_profiles" inverse="true" cascade="all-delete-orphan" lazy="false">
    <key column="company_id" />
    <one-to-many class="com.bla.dataobject.CompanyProfile"/>
 </set>
</class>

<class name="com.bla.dataobject.CompanySiteData" table="company_sites">
    <id name="siteId" column="site_id">
        <generator class="increment"/>
    </id>

   <property name="siteProxySettings" column="PROXY_SETTINGS" type="java.lang.String"/>
   .................
   <property name="siteName" column="SITE_NAME" type="java.lang.String"/>


   <many-to-one name="companyData" class="com.bla.dataobject.CompanyData" column="company_id" not-null="true"/>

</class>

<class name="com.bla.dataobject.CompanyProfile" table="company_profiles">
 <id name="profileId" column="profile_id">
  <generator class="increment"/>
 </id>

 <property ............./>

 <many-to-one name="companyData" class="com.bla.dataobject.CompanyData" column="company_id" not-null="true"/>

</class>

The insert and delete works just fine, but not the update. My application has Axis2 servlet on one side and the hibernate on the other. I'm suppling the Company object to the presentation layer via the SOAP, then the presentation layer makes changes to the object and requesting to persist the changes (the returned back object has hibernate id inside). If I just making the update session.update(object); the collection are not updated (but only the Company flat parameters), if I'm getting stored company object from db and perform a merge within 2 objects (like delete all collections and insert a received one and then update a original object) works only if all collection items are new (otherwise I get DB unique constraint on a collection name in the table that already exist). So my questions are: 1. Is it right to try updating "parent object" or it is needed to update all 3 objects separately? 2. What is the right way to update collections (add/remove/update)

I'll really appreciate code example (that I didn't find myself) with collections handling.

Thanks a lot

1 Answer 1

1
  1. try saveorupdate method
  2. set the hibernate.show_sql = true in configuration xml and check the log infomation
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.