当前位置: 首页 > 知识库问答 >
问题:

如何查询和选择嵌入式id列

子车桐
2023-03-14

我在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 ]

共有1个答案

刘奇
2023-03-14
String stmt = "select txn.id.txnid from TbTxn txn where txn.id.txndttm >= SYSDATE ";

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

 类似资料:
  • 我使用的是Eclipselink(JPA)+GlassFish V3.1.2+NetBeans 7.1.2 我有一个带有复合主键的表:

  • 我正在使用Spring数据jpa来创建服务。使用我从多个表中提取记录。我在模型类中使用了映射。模型类与和进行映射。相符。 我只想从建筑中选择建筑名称。 谁能告诉我怎么办? 查询DSL 结果

  • 问题内容: 我有2个表分别命名为项目和任务 在项目表中,我有: 在任务表中,我有: 现在,我该如何从任务表中选择*并在表任务中通过“ project_id”从项目表中获得“名称”? 谢谢 问题答案: 即使项目表中没有记录,使用左联接也可以确保您有所收获。如果要确保连贯性,可以这样做

  • 问题内容: 我的SQL代码如下: 等效的linq表达式是什么? 问题答案: 我第一次尝试在 来源 LINQ to SQL中的NOT IN子句

  • GroupIdDeliveryStatusReport的结构 如果我不能恰当地描述,请原谅我。 我就是这样写的

  • 问题内容: 让我以简单的方式向您展示 此查询在phpmysql上同时运行正常,但在.php页面上查询时未检测到原始数据 我只是在建立英语至马拉雅拉姆语和马拉雅拉姆语至英语词典 该网站是http://www.chatfitness.com/ 从mysql接收到malayalam单词,在英语单词的基础上可以正常工作。 不幸的是,收到英语单词不能正常工作:( 我对两个函数使用相同的查询,这是用英文单词搜