Hi, I am trying to change all hbm files to annotation based .
Take my hbm file below, <hibernate-mapping> <class name="com.wipro.wiprosrm.utils.vo.FeedSummaryVO" table="feed_summary"> <composite-id name="feedSummaryPK"> <key-property name="orgId" column="org_id"/> <key-property name="channelId" column="channel_id"/> <key-property name="keyword" column="keyword"/> <key-property name="summarizeDate" column="summarize_date" type="date"/> </composite-id> <property name="hitCount" column="hit_count"/> </class> </hibernate-mapping> I have changed as Annotation based(see below)
@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: If i use hbm file, i am able to read,save and update the FeedSummaryVO object if i use annotation based, i am able to read and save but i am getting the following error when i am doing the update
[color=#FF0000org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1[/color]I am using session.merge(obj). i tried with session.update() and session.saveOrUpate() also.
Kindly guide me how to resolve this issue
Thanks, John
|