1

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

<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="contentrepo"。谁能告诉我如何绕过这个问题?

4

1 回答 1

1

将 SQLQuery 转换为 QueryPos 后添加实体。更改您的代码,如下所示:

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();

于 2014-12-03T11:31:05.923 回答