Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用IN运算符的Liferay自定义sql_Liferay - Fatal编程技术网

使用IN运算符的Liferay自定义sql

使用IN运算符的Liferay自定义sql,liferay,Liferay,我正在使用Liferay 6.1、Tomcat和MySQL。我有一个列表portlet的自定义sql语句。自定义sql使用两个参数:GroupID数组和结果限制 SELECT count(articleId) as count, ... FROM comments WHERE groupId IN (?) GROUP BY articleId ORDER BY count DESC LIMIT 0, ? 我的FinderImpl类具有以下方法: public List<Comment

我正在使用Liferay 6.1、Tomcat和MySQL。我有一个列表portlet的自定义sql语句。自定义sql使用两个参数:GroupID数组和结果限制

SELECT
count(articleId) as count,
...
FROM comments
WHERE groupId IN (?)
GROUP BY articleId
ORDER BY count DESC 
LIMIT 0, ?
我的FinderImpl类具有以下方法:

 public List<Comment> findByMostCommented(String groupIds, long maxItems) {

    Session session = null;
    session = openSession();

    String sql = CustomSQLUtil.get(FIND_MOST_COMMENTS);

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity("Comment", CommentImpl.class);

    QueryPos queryPos = QueryPos.getInstance(query);
    queryPos.add(groupIds);
    queryPos.add(maxItems);

    List<Comment> queryResult = query.list();

    return queryResult;
}
公共列表findByMostCommented(字符串组ID,长maxItems){
会话=空;
session=openSession();
字符串sql=CustomSQLUtil.get(查找大多数注释);
SQLQuery=session.createSQLQuery(sql);
查询补遗(“注释”,CommentImpl.class);
QueryPos QueryPos=QueryPos.getInstance(查询);
添加(groupid);
queryPos.add(maxItems);
List queryResult=query.List();
返回查询结果;
}
这将返回0个结果。如果我删除WHERE IN(),它将起作用


是否在有效的运算符中?如果没有,如何在不同的组中进行搜索?

也许hibernate引用了您的组ID字符串(大概是以
“1,2,3,4”
的形式,当hibernate将其转换为sql时,它会为您在字符串周围加引号

您可能想尝试以下内容(来自Liferay本身):


并且在SQL中包含
([$GROUP\U IDS$)
来代替
(?)

好吧,JDBC
PreparedStatement
(Liferay可能在内部使用)不支持为
in
子句中的
传递数组。这可能是由于这个原因。请检查
QueryPos
对象是否提供了执行此操作的API。
String sql = CustomSQLUtil.get(FIND_BY_C_C);

sql = StringUtil.replace(sql, "[$GROUP_IDS$]", groupIds);