Hey guys,
I'm trying to write data to a foreign key field using hibernate's 'saveOrUpdate' method, but it fails to write to my foreign key field. I tried using hibernate's 'update' method, but it does not work either. So, I wondering what I'm doing wrong.
The following is my code:
<hibernate-mapping>
<class name="com.PBCoreApp.datamodel.BusinessCbo" table="Busines" schema="dbo" catalog="PB">
<id name="businessId" type="java.lang.Integer">
<column name="Business_Id" />
<generator class="identity"></generator>
</id>
....
<many-to-one name="placeOfBusiness" class="com.PBCoreApp.datamodel.PlaceOfBusinessCbo" fetch="select">
<column name="Place_Of_Business_Id" />
</many-to-one>
</class>
</hibernate-mapping>
-----------------------------------
<hibernate-mapping>
<class name="com.PBCoreApp.datamodel.PlaceOfBusinessCbo" table="Place_Of_Business" schema="dbo" catalog="PB">
<id name="placeOfBusinessId" type="java.lang.Integer">
<column name="Place_Of_Business_Id" />
<generator class="identity"></generator>
</id>
<set name="busineses" inverse="true" cascade="all-delete-orphan">
<key>
<column name="Place_Of_Business_Id" />
</key>
<one-to-many class="com.PBCoreApp.datamodel.BusinessCbo" />
</set>
</class>
</hibernate-mapping>
-------------------------------------
JAVA CODE
-------------------------------------
public void saveOrUpdate(BusinessCbo businessCbo) {
this.getHibernateTemplate().saveOrUpdate(businessCbo);
this.getHibernateTemplate().flush();
this.getHibernateTemplate().clear();
}
-----------------------------------------
placeOfBusinessCbo = placeOfBusinessDao.findById(pobId);
businessCbo.setPlaceOfBusiness(placeOfBusinessCbo);
businessDao.saveOrUpdate(businessCbo);
-------------------------------------------------------------
Pls...Help!!!
|