【发布时间】:2018-01-29 07:14:18
【问题描述】:
我在 java 中有两个类,即 txn 和 txnID,我想从嵌入式表中检索 txnid 值,下面是我的 txn 类结构:
public class TbTxn implements Serializable{
@EmbeddedId
private TbTxnId id;
private Long acctid;
private String hmbrchcd;
private String crdno;
//all the getter and setter code
}
这是嵌入的类结构:
@Embeddable
public class TbTxnId implements Serializable{
private Date txndttm;
private Long txnid;
@Column(name="TXNDTTM")
public Date getTxndttm() {
return txndttm;
}
public void setTxndttm(Date txndttm) {
this.txndttm = txndttm;
}
@Column(name="TXNID")
public Long getTxnid() {
return txnid;
}
public void setTxnid(Long txnid) {
this.txnid = txnid;
}
}
我的查询语句如下:
String stmt = "select txn.id.TXNID from TbTxn txn where txn.id.TXNDTTM >= SYSDATE ";
Long count = (Long) getSession().createQuery(stmt).uniqueResult();
错误信息如下:
SEVERE: Servlet.service() for servlet [] in context with path [] threw exception [Request processing failed; nested exception is
org.hibernate.QueryException: could not resolve property: id.TXNID of: com.domain.TbTxn [select txn.id.TXNID from com.domain.TbTxn txn where txn.id.TXNDTTM >= SYSDATE ]] with root cause
org.hibernate.QueryException: could not resolve property: id.TXNID of: com.domain.TbTxn [select txn.id.TXNID from com.domain.TbTxn txn where txn.id.TXNDTTM >= SYSDATE ]
【问题讨论】:
标签: java jpa hql composite-key