以下是自定义 SQL:
SELECT COUNT(*)
FROM EEC_Order
WHERE DATE(EEC_Order.createDate) = CURDATE()
AND EEC_Order.status = ?
AND EEC_Order.companyId = ?
上面的 sql 查询在 mysql 中工作但不工作自定义 sql 登录 liferay
public class OrderFinderImpl extends BasePersistenceImpl<Order> implements OrderFinder {
public int getTodayOrderCount(String status,long companyId) {
Session session = null;
SQLQuery query = null;
try {
String sql = CustomSQLUtil.get(GET_TODAY_ORDER_COUNT);
session = openSession();
query = session.createSQLQuery(sql);
query.addEntity("Order", OrderImpl.class);
QueryPos qPos = QueryPos.getInstance(query);
qPos.add(status);
qPos.add(companyId);
Iterator<Long> itr = query.list().iterator();
if (itr.hasNext()) {
Long count = itr.next();
if (count != null) {
return count.intValue();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
closeSession(session);
}
return 0;
}
public static String GET_TODAY_ORDER_COUNT = "getTodayOrderCount";
}
控制台异常:
04:56:56,520 ERROR [http-bio-8080-exec-6][JDBCExceptionReporter:76] Column 'orderId' not found.
com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException: could not execute query
at com.liferay.portal.dao.orm.hibernate.ExceptionTranslator.translate(ExceptionTranslator.java:30)
at com.liferay.portal.dao.orm.hibernate.SQLQueryImpl.list(SQLQueryImpl.java:111)
at com.liferay.portal.dao.orm.hibernate.SQLQueryImpl.list(SQLQueryImpl.java:88)
at com.esquare.ecommerce.service.persistence.OrderFinderImpl.getTodayOrderCount(OrderFinderImpl.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:320)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at com.liferay.portal.dao.shard.advice.ShardPersistenceAdvice.invoke(ShardPersistenceAdvice.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy426.getTodayOrderCount(Unknown Source)