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
|