Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: DynamicQuery for Date doesn't work
Hi
my liferay version is 6.2
database is MySQL 5.6
my dynamic query always return empty list. the column "recordedDate" is DATETIME type.
i have no idea why it just doesn't work.
please help
private DynamicQuery getDynamicQuery() {<br>
ClassLoader classLoader = (ClassLoader)
PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
Constant.PORTLET_CLASS_LOADER_NAME_FOR_CREATE_DYNAMIC_QUERY_OBJECT);<br>
return DynamicQueryFactoryUtil.forClass(Serial_Number.class,
classLoader);<br> }<br> public List<Serial_Number>
getList(Date recordedFrom, Date recordedTo, boolean masterOnly)
throws SystemException {<br> DynamicQuery dynamicQuery =
this.getDynamicQuery();<br> if (recordedFrom == null ||
recordedTo == null) {<br> if (recordedFrom != null)
{<br>
dynamicQuery.add(RestrictionsFactoryUtil.ge("recordedDate",
recordedFrom));<br> }<br> if (recordedTo
!= null) {<br>
dynamicQuery.add(RestrictionsFactoryUtil.le("recordedDate",
recordedTo));<br> }<br> } else {<br>
dynamicQuery.add(RestrictionsFactoryUtil.between("recordedDate",
recordedFrom, recordedTo));<br> }
if (masterOnly) {<br>
dynamicQuery.add(PropertyFactoryUtil.forName("parentSuffixOfSerialNumber").eq(Long.valueOf(0)));<br>
}<br> List<Serial_Number> list =
this.dynamicQuery(dynamicQuery);<br> if (list.size() >
0) {<br> LOGGER.info("have data");<br>
} else {<br> LOGGER.info("no
data");<br> }<br> return list;<br> }
thank you.
ps. I don't know how to use this new UI... can any one tell me how to mark Code?
Hi Bwi Scarletake,
Try getting the real SQL generated by hibernate and execute it directly to your database.
You can dump the SQL using P6Spy, see:
With the SQL you can investigate the root cause of your problem.
Powered by Liferay™