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: Delete old AuditEvent entries
Hi,
is there a possibility to configure a "time to
live" for AUDIT_AUDITEVENT entries?
If not, I would like
to delete old entries with a cleanup job. The problem is that the
following dynamic query throws an exception:
List<AuditEvent> auditEventList = AuditEventUtil.findWithDynamicQuery(
DynamicQueryFactoryUtil.forClass(AuditEvent.class, getClass().getClassLoader())
.add(RestrictionsFactoryUtil.lt("createDate",
Date.from(LocalDate.now().minusDays(days).atStartOfDay(ZoneId.systemDefault()).toInstant()))));
for (AuditEvent auditEvent : auditEventList) {
AuditEventUtil.remove(auditEvent.getAuditEventId());
}
Exception:
org.hibernate.MappingException: Unknown entity: com.liferay.portal.security.audit.storage.model.AuditEvent
If I use AuditEventImpl instead of AuditEvent, it works in debug mode (with "Evaluate Expression"). But when I try to deploy the jar, the following error occurs:
org.osgi.framework.BundleException: Could not resolve module: at.econtrol.form.service [1158]_ Unresolved requirement: Import-Package: com.liferay.portal.security.audit.storage.model.impl_ [Sanitized]
Do you see why this query is not working, or can you suggest me a better way to delete old AuditEvent entries? I would be very grateful for any help.
Hi,
You can try getting a DynamicQuery from AuditEventLocalService and perform your action.
Ex.
DynamicQuery dynamicQuery = _auditEventLocalService.dynamicQuery().add(RestrictionsFactoryUtil.lt("createDate",
Date.from(LocalDate.now().minusDays(30).atStartOfDay(ZoneId.systemDefault()).toInstant())));
List<AuditEvent> auditEvents = AuditEventLocalServiceUtil.dynamicQuery(dynamicQuery);
Also consider referring to Actionable Dynamic Query; this could be helpful for performing action on a large number of records.Refer
Powered by Liferay™