我在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
有人能告诉我这里有什么问题吗?或者我错过了什么?
答案 0 :(得分:4)
你必须把它写成 primary Key.userId,因为您已将userid定义为主键,因此,hibernate期望用户ID前缀为主键。