我有一个查询,当我使用NativeQuery时工作正常,但我需要使用EJB查询来解决我的问题。任何人都可以帮我重新格式化我的查询,这样它也适用于EJB吗?
这是Native版本
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的类是实体类型。属性如下
@Id
private Long Id;
@Column(nullable = false)
private String Name;
@Column(length = 30, nullable = false)
private Timestamp CreationDate;
属性与上面的setter和getter一样。 (除了ID) 感谢
答案 0 :(得分:0)
SELECT DISTINCT
TRUNC(CreationDate) as a
FROM
(SELECT CreationDate FROM myTable ORDER BY CreationDate DESC)
答案 1 :(得分: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]);
}