Search code examples
liferayliferay-6dynamicquery

Facing Exception in Liferay: org.hibernate.QueryException: could not resolve property


I am having service entity defined in service.xml as below:

<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>

And I am trying to fetch rows using dynamicQuery as defined in LocalServiceImpl class.

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

But last line in above code throws exception as

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

Can someone tell me what is wrong here? OR I am missing anything?


Solution

  • You have to write it as primaryKey.userId, as you have defined the userid as Primary key so, hibernate expect the userid prefixes with primaryKey.