0
我有一個POJO映射到存儲過程的結果。休眠SqlResultSetMapping相同的結果重複而不是唯一的
@NamedNativeQueries({
@NamedNativeQuery(name="Pojo.getNotification",
query="call SP_GET_NOTIFICATIONS()",
resultSetMapping = "notificationMapping",
resultClass = Pojo.class,
hints = {@QueryHint(name="org.hibernate.cacheable", value="false")}
)
}
)
@SqlResultSetMapping(name="notificationMapping",
entities = {
@EntityResult(
entityClass = Pojo.class,
fields={
@FieldResult(name="memberId", column="MBR_ID"),
@FieldResult(name="programId", column="PROG_ID")
}
)
}
)
@Entity
public class Pojo {
@Id
private Integer memberId;
private Integer programId;
public Integer getMemberId() {
return memberId;
}
public void setMemberId(Integer memberId) {
this.memberId = memberId;
}
public Integer getProgramId() {
return programId;
}
public void setProgramId(Integer programId) {
this.programId = programId;
}
}
存儲過程是這樣的
CREATE PROCEDURE SCHEMA.SP_GET_NOTIFICATIONS()
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C2 CURSOR WITH HOLD WITH RETURN TO CLIENT FOR
SELECT DISTINCT MBR.MBR_ID AS "MBR_ID",
PROG.MBR_PGM_ID AS "PROG_ID"
FROM SCHEMA.MEMBER_TBL MBR, SCHEMA.MEMBER_PGM_TBL PROG where MBR.SOMETHING = PROG.SOMETHING;
OPEN C2;
END
我這樣調用
List<?> resultSet = mySessionFactory
.getCurrentSession()
.getNamedQuery(
"Pojo.getNotification")
.setCacheable(false).setCacheMode(CacheMode.REFRESH).list();
命名的本地查詢如果我運行蟾蜍的選擇查詢,我看到了兩個不同的記錄。不過,如果我通過迭代的resultSet,我看到的只有一個出現兩次記錄:
[getMemberId()=114, getProgramId()=111]
[getMemberId()=114, getProgramId()=111]
不知道,如果映射是錯誤的或我需要實現的東西。順便說一句,我有使用這兩個屬性POJO中定義的hashcode和equals方法。
我使用Hibernate 4.2.7和ehcache。數據庫是DB2。該框架是Spring/Camel。