<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Delete old AuditEvent entries</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121147879" />
  <subtitle>Delete old AuditEvent entries</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121147879</id>
  <updated>2026-04-04T16:19:23Z</updated>
  <dc:date>2026-04-04T16:19:23Z</dc:date>
  <entry>
    <title>RE: Delete old AuditEvent entries</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121164959" />
    <author>
      <name>Mohammed Yasin</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121164959</id>
    <updated>2021-09-24T05:22:45Z</updated>
    <published>2021-09-24T05:18:04Z</published>
    <summary type="html">&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can try getting a DynamicQuery from AuditEventLocalService and
  perform your action.&lt;/p&gt;
&lt;p&gt;Ex.&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;DynamicQuery dynamicQuery = _auditEventLocalService.dynamicQuery().add(RestrictionsFactoryUtil.lt(&amp;quot;createDate&amp;quot;,
				Date.from(LocalDate.now().minusDays(30).atStartOfDay(ZoneId.systemDefault()).toInstant())));

List&amp;lt;AuditEvent&amp;gt; auditEvents = AuditEventLocalServiceUtil.dynamicQuery(dynamicQuery);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also consider referring to Actionable Dynamic Query; this could be
  helpful for performing action on a large number of records.&lt;a href="https://help.liferay.com/hc/en-us/articles/360018166071-Actionable-Dynamic-Queries"&gt;Refer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Mohammed Yasin</dc:creator>
    <dc:date>2021-09-24T05:18:04Z</dc:date>
  </entry>
  <entry>
    <title>Delete old AuditEvent entries</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121147878" />
    <author>
      <name>Stefan Holzer</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121147878</id>
    <updated>2021-10-04T17:11:03Z</updated>
    <published>2021-09-15T09:22:30Z</published>
    <summary type="html">&lt;p&gt;Hi,&lt;br /&gt; is there a possibility to configure a &amp;quot;time to
  live&amp;quot; for AUDIT_AUDITEVENT entries? &lt;br /&gt; If not, I would like
  to delete old entries with a cleanup job. The problem is that the
  following dynamic query throws an exception:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;List&amp;lt;AuditEvent&amp;gt; auditEventList = AuditEventUtil.findWithDynamicQuery(
      DynamicQueryFactoryUtil.forClass(AuditEvent.class, getClass().getClassLoader())
            .add(RestrictionsFactoryUtil.lt(&amp;quot;createDate&amp;quot;,
                  Date.from(LocalDate.now().minusDays(days).atStartOfDay(ZoneId.systemDefault()).toInstant()))));
for (AuditEvent auditEvent : auditEventList) {
   AuditEventUtil.remove(auditEvent.getAuditEventId());
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Exception:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;org.hibernate.MappingException: Unknown entity: com.liferay.portal.security.audit.storage.model.AuditEvent
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If I use AuditEventImpl instead of AuditEvent, it works in debug mode
  (with &amp;quot;Evaluate Expression&amp;quot;). But when I try to deploy the
  jar, the following error occurs:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;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]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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.&lt;/p&gt;</summary>
    <dc:creator>Stefan Holzer</dc:creator>
    <dc:date>2021-09-15T09:22:30Z</dc:date>
  </entry>
</feed>
