• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saveOrUpdate and Update function not working

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your suggestion, but that still did not work.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic