-->
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.  [ 8 posts ] 
Author Message
 Post subject: Update operation using composite id
PostPosted: Mon Jun 04, 2007 2:55 am 
Newbie

Joined: Fri Jun 01, 2007 6:10 am
Posts: 5
Hi,

I m using Hibernate3 and SQL Server.
There is no primary Key in my table.

Insert and Delete operation are working properly but When I Try to update a record.....It niether Update record nor giving any error/exception.

My Mapping File is:

<?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.solversa.bean.Ttcmcs047550" table="ttcmcs047550" schema="dbo">
<composite-id name="id" class="com.solversa.bean.Ttcmcs047550Id">
<key-property name="TCkon" type="java.lang.String">
<column name="t_ckon" />
</key-property>
<key-property name="TGrno" type="java.lang.Short">
<column name="t_grno" />
</key-property>
<key-property name="TDsca" type="java.lang.String">
<column name="t_dsca" length="30" />
</key-property>
<key-property name="TFfno" type="java.lang.Integer">
<column name="t_ffno" />
</key-property>
<key-property name="TComp" type="java.lang.Short">
<column name="t_comp" />
</key-property>
<key-property name="TBlck" type="java.lang.String">
<column name="t_blck" />
</key-property>
<key-property name="TRefcntd" type="java.lang.Integer">
<column name="t_Refcntd" />
</key-property>
<key-property name="TRefcntu" type="java.lang.Integer">
<column name="t_Refcntu" />
</key-property>
<key-property name="hash1" type="java.lang.String">
<column name="hash1" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

My code is:

org.hibernate.Query query = session.createQuery("from com.solversa.bean.Ttcmcs047550 " +
"where t_dsca = '"+desc+"' and t_grno = "+serialNo+
" and t_ffno = "+ffNum+" and t_comp = "+company);

Iterator iterate=query.iterate();

if(iterate.hasNext())
{
//Create the object to retrieve value from list
Ttcmcs047550 ttcmcs047550=(Ttcmcs047550)iterate.next();
Ttcmcs047550 t_data=(Ttcmcs047550)session.get(Ttcmcs047550.class,ttcmcs047550.getId());

t_data.getId().setTDsca(NewDesc);
session.update(t_data);

}

Does anyone have any idea why UPDATE operation isn't performed.

Thanks.


Last edited by Kinshu on Mon Jun 04, 2007 6:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Update operation using composite id
PostPosted: Mon Jun 04, 2007 6:02 am 
Newbie

Joined: Mon May 28, 2007 2:25 am
Posts: 9
Hi Kinshu.....

Sorry we have not work with Composite ID......

hope so some other poerson will give you the anser that you want.


Byeeeeeeeee

Kinshu wrote:
Hi,

I m using Hibernate3 and SQL Server.
There is no primary Key in my table.

Insert and Delete operation are working properly but When I Try to update a record.....It niether Update record nor giving any error/exception.

My Mapping File is:

<?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.solversa.bean.Ttcmcs047550" table="ttcmcs047550" schema="dbo">
<composite-id name="id" class="com.solversa.bean.Ttcmcs047550Id">
<key-property name="TCkon" type="java.lang.String">
<column name="t_ckon" />
</key-property>
<key-property name="TGrno" type="java.lang.Short">
<column name="t_grno" />
</key-property>
<key-property name="TDsca" type="java.lang.String">
<column name="t_dsca" length="30" />
</key-property>
<key-property name="TFfno" type="java.lang.Integer">
<column name="t_ffno" />
</key-property>
<key-property name="TComp" type="java.lang.Short">
<column name="t_comp" />
</key-property>
<key-property name="TBlck" type="java.lang.String">
<column name="t_blck" />
</key-property>
<key-property name="TRefcntd" type="java.lang.Integer">
<column name="t_Refcntd" />
</key-property>
<key-property name="TRefcntu" type="java.lang.Integer">
<column name="t_Refcntu" />
</key-property>
<key-property name="hash1" type="java.lang.String">
<column name="hash1" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

My code is:

org.hibernate.Query query = session.createQuery("from com.solversa.bean.Ttcmcs047550 " +
"where t_dsca = '"+desc+"' and t_grno = "+serialNo+
" and t_ffno = "+ffNum+" and t_comp = "+company);

Iterator iterate=query.iterate();

if(iterate.hasNext())
{
//Create the object to retrieve value from list
Ttcmcs047550 ttcmcs047550=(Ttcmcs047550)iterate.next();
Ttcmcs047550 t_data=(Ttcmcs047550)session.get(Ttcmcs047550.class,ttcmcs047550.getId());

t_data.getId().setTDsca(NewDesc);
session.update(ttcmcs047550);

}

Does anyone have any idea why UPDATE operation isn't performed.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 6:23 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

You are loading a object t_data and you are going to update object ttcmcs047550
it should
session.update(t_data);

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 6:44 am 
Newbie

Joined: Fri Jun 01, 2007 6:10 am
Posts: 5
Thanks but it does not make any diffence in result...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 6:56 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi


You can use two methods

session.saveorUpdate(t_data);

or

session.update with serId


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:12 am 
Newbie

Joined: Fri Jun 01, 2007 6:10 am
Posts: 5
Hi,

Thanks again....

But I have tried saveOrUpadate method but it is also not giving any result.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:12 am 
Newbie

Joined: Fri Jun 01, 2007 6:10 am
Posts: 5
Hi,

Thanks again....

But I have tried saveOrUpadate method but it is also not giving any result.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:13 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
With Hibernate you CAN'T modify a key value.


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

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.