Liferay CustomSQL表不存在

时间:2014-12-02 09:37:55

标签: liferay liferay-service-builder

我有一个服务实体声明如下:

<entity name="MyContentRepo" local-service="true" remote-service="true" table="contentrepo">
</entity>

我正在尝试使用自定义SQL来获取一些细节:

session = openSession();
String sqlQueryString = CustomSQLUtil.get("query_id");
SQLQuery query = session.createSQLQuery(sqlQueryString);
query.addEntity("MyContentRepo", MyContentRepoImpl.class);
QueryPos qPos = QueryPos.getInstance(query);
qPos.add("someparameter");
list = (List<MyContentRepo>) query.list();

但是我在执行时遇到以下错误:

08:02:26,640 ERROR [http-bio-8090-exec-72][JDBCExceptionReporter:82] Table 'mysqldb.mycontentrepo' doesn't exist
com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException: could not execute query

查询采用声明的实体的名称而不是table =&#34; contentrepo&#34;。有谁能告诉我如何绕过这个问题?

1 个答案:

答案 0 :(得分:1)

将SQLQuery转换为QueryPos后,

AddEntity。如下所示更改您的代码:

session = openSession();

String sqlQueryString = CustomSQLUtil.get("query_id"); SQLQuery query = session.createSQLQuery(sqlQueryString);

QueryPos qPos = QueryPos.getInstance(query); qPos.add("someparameter");

query.addEntity("MyContentRepo", MyContentRepoImpl.class); list = (List<MyContentRepo>) query.list();