3

我在 service.xml 中定义了服务实体,如下所示:

<entity name="LoginData" local-service="true" remote-service="false"> <!-- PK fields --> <column name="userId" type="long" primary="true" /> <column name="loginDate" type="Date" primary="true" /> </entity>

我正在尝试使用 LocalServiceImpl 类中定义的 dynamicQuery 获取行。

DynamicQuery dynamicQuery=DynamicQueryFactoryUtil.forClass(LoginData.class); dynamicQuery.add(RestrictionsFactoryUtil.eq("userId", userId)); dynamicQuery.add(RestrictionsFactoryUtil.between("loginDate", startDate, endDate)); return (List<LoginData>)LoginDataLocalServiceUtil.dynamicQuery(dynamicQuery);

但是上面代码中的最后一行抛出异常

Caused by: org.hibernate.QueryException: could not resolve property: userId of: com.example.model.impl.LoginDataImpl

有人可以告诉我这里有什么问题吗?或者我错过了什么?

4

1 回答 1

4

您必须将其编写为 primaryKey.userId,因为您已将用户 ID 定义为主键,因此休眠期望用户 ID 前缀为 primaryKey。

于 2014-06-21T17:45:04.170 回答