Reputation: 41
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))));
Upvotes: 1
Views: 329
Reputation: 153700
A ProjectionList can contain multiple SQLProjection(s), but each SQLProjection should be associated to one and only one SQL columns.
You SQLProjection tries to select two columns instead.
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();
Upvotes: 1