【问题标题】:How to query and select embedded id column如何查询和选择嵌入的 id 列
【发布时间】: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


    【解决方案1】:
    String stmt = "select txn.id.txnid from TbTxn txn where txn.id.txndttm >= SYSDATE ";
    

    我们应该注意实体类名称及其属性的情况。

    【讨论】:

    • 它也不起作用。收到此错误:期待 IDENT,在第 1 行第 15 列附近找到“”[select txn.id.**TXNID* from com.domain.TbTxn txn where txn.id.TXNDTTM >= SYSDATE]
    • 现在可以了。遵循已声明的确切属性名称
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2013-04-03
    相关资源
    最近更新 更多