[英]Hibernate native query shows exception
I have written hibernate native query for getting total users and month from table. 我写了休眠本机查询,以获取表中的总用户和月份。
But it shows : 但它显示:
exception:Operand should contain 1 column(s)
org.hibernate.exception.DataException: could not execute query
could anyone please help me for solving this: 谁能帮我解决这个问题:
c.setProjection(Projections.projectionList()
.add(Projections.sqlProjection("(select count(*), MONTH(Stored) from adbtbl_stat "
+ "where Activity = 89 and YEAR(Stored) = 2015) as Count, month",
new String[] { "Count", "month" }, new Type[] { LongType.INSTANCE, StringType.INSTANCE }))
.add(Projections.groupProperty(month(stored))));
A ProjectionList can contain multiple SQLProjection(s) , but each SQLProjection should be associated to one and only one SQL columns. 一个ProjectionList可以包含多个SQLProjection ,但是每个SQLProjection应该与一个SQL列关联,并且只能与一个SQL列关联。
You SQLProjection tries to select two columns instead. 您的SQLProjection尝试选择两列。
Try replacing your Criteria query with a simple native query instead: 尝试使用简单的本地查询替换您的条件查询:
Long activity = ...;
int year = ...;
Query q = entityManager.createNativeQuery(
"select count(*) as Count, MONTH(Stored) as Month " +
"from adbtbl_stat " +
"where Activity = :activity and YEAR(Stored) = :year"
);
q.setParameter("activity", activity);
q.setParameter("year", year);
List<Object[]> result = (List<Object[]>) q.getResultList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.