-->
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.  [ 12 posts ] 
Author Message
 Post subject: compositeKey update failure
PostPosted: Mon Aug 29, 2005 4:28 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I am useing Hibernate with Spring. I have a table with no primary key
and trying to update a rwo from UI.

Mapping file
<hibernate-mapping package="com.xxx.model">
<class name="Data" table="tableName">
<composite-id >
<key-property name="scid" column="SCENEID" type="long"></key-property>
<key-property name="penid" column="PERSONID" type="long"></key-property>
<key-property name="neid" column="NODEID" type="long"></key-property>
<key-property name="name" column="NAME" type="java.lang.String"></key-property>
<key-property name="value" column="VALUE" type="java.lang.String"></key-property>
</composite-id>
</class>
</hibernate-mapping>

I tried with save and saveUpdate methods from springTemaplate().
I is not even throughing any exception. I am bale to create,delete,search.
Only update fails.Any help Please Thanks

public void updateData(Data data) throws InfrastructureException{
try {
getHibernateTemplate().saveOrUpdate(data);
} catch (DataAccessException e) {
throw new InfrastructureException(e);
//e.printStackTrace();
}

}

Thanks
Sudhakar


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 4:49 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
The possible reason for failure would be your where clause.
Your where clause may not fetch any data that's why it is not updating.

Could you share the generated update sql.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 4:51 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
It is not even generating sql quuery.

It is generating query for Insert,Delete,Select.

It is not even throwing exception for update

Thanks
Sudhakar


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 4:55 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
sudhakartv wrote:
It is not even generating sql quuery.

It is generating query for Insert,Delete,Select.

It is not even throwing exception for update

Thanks
Sudhakar


I'm pretty sure you're not allowed to update the key so it's possible that Hibernate isn't being made aware the object is changed and is therefore not doing the update.

Is that the complete mapping or are there additional, not composite-id fields as well ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:00 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
That is the content of my mapping file. I have five fields in that table and I have all rights on that table.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:06 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I have three records displaying in UI selected one record-goto edit page and edit couple of columns and submit.

My basic question is how hibernate knows which row I have updated when there is no primary key ?. All five fileds become unique but how will it know which record i have selected and updated ?

Here is example data :

3493 111 666 James James Value
3493 33333 6666 Test2 TestValue2
3493 121212 909090 Sudha123 Sudha Value


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:42 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I alo implimented the two methods in Data bean.

public boolean equals(Object other) {
if ( !(other instanceof Data) ) return false;
Data castOther = (Data) other;
return new EqualsBuilder()
.append(this.getSceneid(), castOther.getSceneid())
.append(this.getPersonid(), castOther.getPersonid())
.append(this.getNodeid(), castOther.getNodeid())
.append(this.getName(), castOther.getName())
.append(this.getValue(), castOther.getValue())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getSceneid())
.append(getPersonid())
.append(getNodeid())
.append(getName())
.append(getValue())
.toHashCode();
}


Any Help please.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 9:14 am 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I am still waiting :)....


Top
 Profile  
 
 Post subject: Simple question but looks complicated to solve
PostPosted: Wed Aug 31, 2005 9:55 am 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
Experties could you please have a look ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:56 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
sudhakartv wrote:
I have three records displaying in UI selected one record-goto edit page and edit couple of columns and submit.

My basic question is how hibernate knows which row I have updated when there is no primary key ?. All five fileds become unique but how will it know which record i have selected and updated ?

Here is example data :

3493 111 666 James James Value
3493 33333 6666 Test2 TestValue2
3493 121212 909090 Sudha123 Sudha Value


Well you've answered yourself haven't you?

If the 5 fields combined identify a record by altering one you've created a new record. Thus preventing you from updating because as far as hibernate is concerned you've got a new record.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:10 am 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
Then hibernate atleast insert a new row in a table right ? When i use SaveOrUpdate methods. But anyway that is not my requirement. So there is no way it can identify the row I am updating and update the record in DB right? unless i select the row with old values and pass new value and update it


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:17 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
You are not updating the record, you can not update the record, stop even thinking about updating the record.

You are using all 5 fields as a composite key, by altering any of them you create a new record.

If this is a legacy database then I can think of no clear way forward apart from evicting the object from the session and using a jdbc connection to alter the row.

If it's not a legacy database then re-consider your design.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.