Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saveOrUpdate and Update function not working

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
placeOfBusinessCbo = placeOfBusinessDao.findById(pobId);

businessCbo.setPlaceOfBusiness(placeOfBusinessCbo);

businessDao.saveOrUpdate(businessCbo);


Does the Set in your PlaceOfBusinessCbo object have the instance of BusinessCbo. Like this:

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your suggestion, but that still did not work.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<many-to-one name="placeOfBusiness" class="com.PBCoreApp.datamodel.PlaceOfBusinessCbo" fetch="select">


You are saving the BusinessCbo which is the child object of PlaceOfBusinessCbo. Why dont you add the cascade attribute to the many-to-one declaration in your BusinessCbo hbm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic