0

我有一个查询,当我使用 NativeQuery 时可以正常工作,但我需要使用 EJB 查询来解决我的问题。谁能帮我重新格式化我的查询,以便它也适用于 EJB?

这里是原生版本

Query query = getEntityManager.createNativeQuery("WITH src as ("
+ "Select distinct TRUNC(CreationDate) a" 
+ "From myTable)"
+ "Select src.a from src Order by src.a desc");

myTable 的 Class 是 Entity 类型。属性如下

    @Id
    private Long Id; 

    @Column(nullable = false)
    private String Name;

    @Column(length = 30, nullable = false)
    private Timestamp CreationDate;

属性与上面的设置器和获取器相同。(身份证除外)谢谢

4

2 回答 2

0

SELECT DISTINCT 
    TRUNC(CreationDate) as a
        FROM 
            (SELECT CreationDate  FROM myTable ORDER BY CreationDate DESC)

于 2014-07-31T17:40:58.227 回答
0

尝试这个:

Query query = getEntityManager.createQuery(
                "select DISTINCT TRUNC(src.CreationDate) 
                   from myTable src 
                  ORDER by src.CreationDate"
              );
List<Object[]> rows = query.list();
for (Object[] row: rows) {
    System.out.println("My date" + row[0]);
}
于 2014-07-31T17:42:07.180 回答