-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate annotation for composite keys
PostPosted: Tue Aug 30, 2011 3:05 am 
Newbie

Joined: Fri Apr 08, 2011 8:44 am
Posts: 8
Hi,
I've used hibernate annotation for composite keys with same table.
Below my pojo code:

@Entity
@Table(name = "feed_summary")
public class FeedSummaryVO implements Serializable{
/**
*/
private static final long serialVersionUID = 1L;
@Id
private FeedSummaryPK feedSummaryPK;
@Column(name = "hit_count")
private int hitCount;

public int getHitCount() {
return hitCount;
}

public void setHitCount(int hitCount) {
this.hitCount = hitCount;
}
}

and ,

@Embeddable
public class FeedSummaryPK implements Serializable{
/**
*/
private static final long serialVersionUID = 1L;
@Column(name = "org_id")
private Long orgId;
@Column(name = "channel_id")
private Long channelId;
@Column(name = "keyword")
private String keyword;
@Column(name = "summarize_date")
private Date summarizeDate;

public FeedSummaryPK(Long orgId,Long channelId,String keyword,Date summarizeDate){
this.orgId = orgId;
this.channelId = channelId;
this.keyword = keyword;
this.summarizeDate = summarizeDate;
}

public FeedSummaryPK(){
}

public Long getOrgId() {
return orgId;
}

public void setOrgId(Long orgId) {
this.orgId = orgId;
}

public Long getChannelId() {
return channelId;
}

public void setChannelId(Long channelId) {
this.channelId = channelId;
}

public String getKeyword() {
return keyword;
}

public void setKeyword(String keyword) {
this.keyword = keyword;
}

public Date getSummarizeDate() {
return summarizeDate;
}

public void setSummarizeDate(Date summarizeDate) {
this.summarizeDate = summarizeDate;
}

public boolean equals(Object arg0) {
if (arg0 == null)
return false;
if (!(arg0 instanceof FeedSummaryPK))
return false;
FeedSummaryPK arg1 = (FeedSummaryPK) arg0;
return (this.orgId.longValue() == arg1.getOrgId().longValue())
&& (this.channelId.longValue() == arg1.getChannelId()
.longValue()) && (this.keyword == arg1.getKeyword())
&& (this.summarizeDate.equals(arg1.getSummarizeDate()));

}

public int hashCode() {
int hsCode;
hsCode = (orgId + channelId + keyword + summarizeDate).hashCode();
hsCode = 19 * hsCode;
System.out.println("hashcode :: "+hsCode);
return hsCode;
}
}
Problem:
Here i can able to read and save the FeedSummaryVO object but when i am going to update the object know ,i am getting the following error:

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

I am using session.merge(obj) only.

Kindly guide me how to resolve this issue

Thanks,
John


Top
 Profile  
 
 Post subject: Re: hibernate annotation for composite keys
PostPosted: Mon Sep 05, 2011 7:29 am 
Newbie

Joined: Fri Apr 08, 2011 8:44 am
Posts: 8
I am expecting someone replay..
Kindly help me to get reslove this issue...


Thanks,
John


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