我有一張複合關鍵字'rid'和'sid'的表。HibernateTemplate複合關鍵字獲取值null
對於我做了以下豆與Hibernate映射註釋:
WBList.java
============
@Entity
@IdClass(WBListPK.class)
public class WBList {
private int rid;
private int sid;
private String wb;
@Id
@JoinColumn(name="rid")
public int getRid() {
return rid;
}
public void setRid(int rid) {
this.rid = rid;
}
@Id
@JoinColumn(name="sid")
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
@Column(name="wb")
public String getWb() {
return wb;
}
public void setWb(String wb) {
this.wb = wb;
}
}
WBListPK.java有下面的代碼:
@Embeddable
public class WBListPK implements Serializable {
private int rid;
private int sid;
private String wb;
public int getRid() {
return rid;
}
public void setRid(int rid) {
this.rid = rid;
}
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getWb() {
return wb;
}
public void setWb(String wb) {
this.wb = wb;
}
}
我WBListDao有以下方法:
//Some other code ...
public WBList getWBListById(WBListPK wbListPK) {
return (WBList) this.hibernateTemplate.get(WBList.class,wbListPK);
}
以下是我的控制器代碼:
WBList wbList = new WBList();
WBListPK wbListPK = new WBListPK();
wbListPK.setRid(1);
wbListPK.setSid(7);
wbList = this.wbListSecurityProcessor.getWBListById(wbListPK);
System.out.println("Wblist = "+wbList);
當我上面的代碼執行時,wbList取空值..
如果任何人有任何解決方案,plz幫助..提前
謝謝...
你能提供任何示例鏈接,顯示相同的? – Nirmal 2009-12-11 11:30:23
http://www.java2s.com/Code/Java/EJB3/MarkEmbeddedId.htm – Bozho 2009-12-11 11:32:51