-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate SaveorUpdate Question
PostPosted: Sun Jul 13, 2008 2:12 am 
Newbie

Joined: Tue Apr 15, 2008 4:56 am
Posts: 5
Hi Everyone,

I am facing a problem with updating database table row. When I am trying it with saveorupdate, it inserts a new value into the table rather than updating. Can anyone please help with this.
Hibernate version: 3.2.4

Mapping documents:
CoursePlan.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.msee.model.entity.CoursePlan" table="course_plan" dynamic-update="true" dynamic-insert="true">
<id name="id" type="java.lang.Integer" unsaved-value="null">
<column name="ID" />
<generator class="increment" />
</id>
<many-to-one name="studentDetails" class="com.msee.model.entity.StudentDetails" fetch="select">
<column name="STUDENT_ID" />
</many-to-one>
<property name="specialization" type="java.lang.String">
<column name="SPECIALIZATION" length="30" />
</property>
<property name="spc1" type="java.lang.String">
<column name="SPC1" length="30" />
</property>
<property name="spc2" type="java.lang.String">
<column name="SPC2" length="30" />
</property>
<property name="spc3" type="java.lang.String">
<column name="SPC3" length="30" />
</property>
<property name="spc4" type="java.lang.String">
<column name="SPC4" length="30" />
</property>
<property name="rc1" type="java.lang.String">
<column name="RC1" length="30" />
</property>
<property name="rc2" type="java.lang.String">
<column name="RC2" length="30" />
</property>
<property name="rc3" type="java.lang.String">
<column name="RC3" length="30" />
</property>
<property name="rc4" type="java.lang.String">
<column name="RC4" length="30" />
</property>
<property name="mc1" type="java.lang.String">
<column name="MC1" length="30" />
</property>
<property name="mc2" type="java.lang.String">
<column name="MC2" length="30" />
</property>
<property name="isThesis" type="java.lang.String">
<column name="IS_THESIS" length="1" />
</property>
<property name="projectWork" type="java.lang.String">
<column name="PROJECT_WORK" length="200" />
</property>
<property name="th1" type="java.lang.String">
<column name="TH1" length="30" />
</property>
<property name="th2" type="java.lang.String">
<column name="TH2" length="30" />
</property>
<property name="th3" type="java.lang.String">
<column name="TH3" length="30" />
</property>
<property name="isSpc1Accept" type="java.lang.String">
<column name="IS_SPC1_ACCEPT" length="1" />
</property>
<property name="isSpc2Accept" type="java.lang.String">
<column name="IS_SPC2_ACCEPT" length="1" />
</property>
<property name="isSpc3Accept" type="java.lang.String">
<column name="IS_SPC3_ACCEPT" length="1" />
</property>
<property name="isSpc4Accept" type="java.lang.String">
<column name="IS_SPC4_ACCEPT" length="1" />
</property>
<property name="isRc1Accept" type="java.lang.String">
<column name="IS_RC1_ACCEPT" length="1" />
</property>
<property name="isRc2Accept" type="java.lang.String">
<column name="IS_RC2_ACCEPT" length="1" />
</property>
<property name="isRc3Accept" type="java.lang.String">
<column name="IS_RC3_ACCEPT" length="1" />
</property>
<property name="isRc4Accept" type="java.lang.String">
<column name="IS_RC4_ACCEPT" length="1" />
</property>
<property name="isMc1Accept" type="java.lang.String">
<column name="IS_MC1_ACCEPT" length="1" />
</property>
<property name="isMc2Accept" type="java.lang.String">
<column name="IS_MC2_ACCEPT" length="1" />
</property>
<property name="isProjectWorkAccept" type="java.lang.String">
<column name="IS_PROJECT_WORK_ACCEPT" length="1" />
</property>
<property name="isTh1Accept" type="java.lang.String">
<column name="IS_TH1_ACCEPT" length="1" />
</property>
<property name="isTh2Accept" type="java.lang.String">
<column name="IS_TH2_ACCEPT" length="1" />
</property>
<property name="isTh3Accept" type="java.lang.String">
<column name="IS_TH3_ACCEPT" length="1" />
</property>
<set name="planScheduleDetailses" inverse="true" cascade="all">
<key>
<column name="ID" />
</key>
<one-to-many class="com.msee.model.entity.PlanScheduleDetails" />
</set>
</class>
</hibernate-mapping>

PlanScheduleDetails.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.msee.model.entity.PlanScheduleDetails" table="plan_schedule_details" dynamic-update="true" dynamic-insert="true">
<id name="scheduleId" type="java.lang.Integer" unsaved-value="null">
<column name="schedule_id" />
<generator class="increment" />
</id>
<many-to-one name="coursePlan" class="com.msee.model.entity.CoursePlan" fetch="select">
<column name="ID" />
</many-to-one>
<property name="sp1grade" type="java.lang.String">
<column name="sp1grade" length="10" />
</property>
<property name="sp2grade" type="java.lang.String">
<column name="sp2grade" length="10" />
</property>
<property name="sp3grade" type="java.lang.String">
<column name="sp3grade" length="10" />
</property>
<property name="sp4grade" type="java.lang.String">
<column name="sp4grade" length="10" />
</property>
<property name="rc1grade" type="java.lang.String">
<column name="rc1grade" length="10" />
</property>
<property name="rc2grade" type="java.lang.String">
<column name="rc2grade" length="10" />
</property>
<property name="mc1grade" type="java.lang.String">
<column name="mc1grade" length="10" />
</property>
<property name="mc2grade" type="java.lang.String">
<column name="mc2grade" length="10" />
</property>
<property name="th1grade" type="java.lang.String">
<column name="th1grade" length="10" />
</property>
<property name="th2grade" type="java.lang.String">
<column name="th2grade" length="10" />
</property>
<property name="th3grade" type="java.lang.String">
<column name="th3grade" length="10" />
</property>
<property name="sp1startTermYear" type="java.lang.String">
<column name="sp1start_term_year" length="20" />
</property>
<property name="sp1endTermYear" type="java.lang.String">
<column name="sp1end_term_year" length="10" />
</property>
<property name="sp2startTermYear" type="java.lang.String">
<column name="sp2start_term_year" length="10" />
</property>
<property name="sp2endTermYear" type="java.lang.String">
<column name="sp2end_term_year" length="10" />
</property>
<property name="sp3startTermYear" type="java.lang.String">
<column name="sp3start_term_year" length="20" />
</property>
<property name="sp3endTermYear" type="java.lang.String">
<column name="sp3end_term_year" length="10" />
</property>
<property name="sp4startTermYear" type="java.lang.String">
<column name="sp4start_term_year" length="10" />
</property>
<property name="sp4endTermYear" type="java.lang.String">
<column name="sp4end_term_year" length="10" />
</property>
<property name="rc1startTermYear" type="java.lang.String">
<column name="rc1start_term_year" length="20" />
</property>
<property name="rc1endTermYear" type="java.lang.String">
<column name="rc1end_term_year" length="10" />
</property>
<property name="rc2startTermYear" type="java.lang.String">
<column name="rc2start_term_year" length="10" />
</property>
<property name="rc2endTermYear" type="java.lang.String">
<column name="rc2end_term_year" length="10" />
</property>
<property name="rc3startTermYear" type="java.lang.String">
<column name="rc3start_term_year" length="10" />
</property>
<property name="rc3endTermYear" type="java.lang.String">
<column name="rc3end_term_year" length="10" />
</property>
<property name="rc4startTermYear" type="java.lang.String">
<column name="rc4start_term_year" length="10" />
</property>
<property name="rc4endTermYear" type="java.lang.String">
<column name="rc4end_term_year" length="10" />
</property>
<property name="mc1startTermYear" type="java.lang.String">
<column name="mc1start_term_year" length="20" />
</property>
<property name="mc1endTermYear" type="java.lang.String">
<column name="mc1end_term_year" length="10" />
</property>
<property name="mc2startTermYear" type="java.lang.String">
<column name="mc2start_term_year" length="10" />
</property>
<property name="mc2endTermYear" type="java.lang.String">
<column name="mc2end_term_year" length="10" />
</property>
<property name="th1startTermYear" type="java.lang.String">
<column name="th1start_term_year" length="20" />
</property>
<property name="th1endTermYear" type="java.lang.String">
<column name="th1end_term_year" length="10" />
</property>
<property name="th2startTermYear" type="java.lang.String">
<column name="th2start_term_year" length="10" />
</property>
<property name="th2endTermYear" type="java.lang.String">
<column name="th2end_term_year" length="10" />
</property>
<property name="th3startTermYear" type="java.lang.String">
<column name="th3start_term_year" length="20" />
</property>
<property name="th3endTermYear" type="java.lang.String">
<column name="th3end_term_year" length="10" />
</property>
<property name="projectgrade" type="java.lang.String">
<column name="projectgrade" length="10" />
</property>
<property name="projectstartTermYear" type="java.lang.String">
<column name="projectstart_term_year" length="20" />
</property>
<property name="projectendTermYear" type="java.lang.String">
<column name="projectend_term_year" length="10" />
</property>
<property name="rc3grade" type="java.lang.String">
<column name="rc3grade" length="10" />
</property>
<property name="rc4grade" type="java.lang.String">
<column name="rc4grade" length="10" />
</property>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

private boolean updateDatabase(BaseDAOBean objBean, int pOperationStr)
throws HibernateException
{
boolean isSuccess = false;
Session session = getSession();

Transaction trx = session.beginTransaction();
try
{
switch(pOperationStr)
{
case 1: // '\001'
System.out.println("Adding ...");
// session.save(objBean);
session.saveOrUpdate(objBean);
trx.commit();

System.out.println("Adding ...complete");
break;

}



Name and version of the database you are using: MySql 5.0



Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.