0
無法從NamedQuery獲取整數?JPA Eclipselink NamedQuery vs查詢COUNT
@NamedQuery( name = Comm.COUNTLIKEVALUEINHOLDER,
query = "SELECT COUNT(c.id) " +
"FROM Comm c " +
"JOIN c.element e " +
"WHERE c.search1 LIKE :search1 " +
"AND c.search2 = :search2 " +
"AND c.type = :type " +
"AND e.holderelement = :holder"
)
Object q = em.createNamedQuery(Comm.COUNTLIKEVALUEINHOLDER)
.setParameter("search1", "bla%")
.setParameter("search2", "bla2")
.setParameter("type", t)
.setParameter("holder", h)
.getSingleResult();
我從一個COUNT聚集中得到一個實體,而不是一個Long或Integer。
但是我在這裏得到了一個Integer。這完全是同一個查詢。
Object i = em.createQuery("SELECT COUNT(c.id) " +
"FROM Comm c " +
"JOIN c.element e " +
"WHERE c.search1 LIKE :search1 " +
"AND c.search2 = :search2 " +
"AND c.type = :type " +
"AND e.holderelement = :holder")
.setParameter("search1", "bla%")
.setParameter("search2", "bla2")
.setParameter("type", t)
.setParameter("holder", h)
.getSingleResult();
有沒有人有想法?