如何查询和 select 嵌入的 id 列

How to query and select embedded id column

我在 java 中有两个 class 是 txn 和 txnID,我想从嵌入式 table 中检索 txnid 值,下面是我的 txn class 结构:

public class TbTxn implements Serializable{

@EmbeddedId
private TbTxnId id;

private Long   acctid;
private String hmbrchcd;
private String crdno;
//all the getter and setter code
}

这里是嵌入式 class 结构:

@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 ]
String stmt = "select txn.id.txnid from TbTxn txn where txn.id.txndttm >= SYSDATE ";

我们应该处理实体 class 名称及其属性的情况。