Message Boards
Delete old AuditEvent entries
Delete old AuditEvent entries
New Member Post: 1 Join Date: 9/15/21 Recent PostsHi,
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.
RE: Delete old AuditEvent entries
Liferay Master Posts: 591 Join Date: 8/8/14 Recent PostsHi,
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