[OpenNMS/opennms] 787780: NMS-20161: Apply criteria fetch modes after the di...

Marshall Massengill via opennms-cvs <[email protected]>
Newsgroups gmane.network.opennms.cvs
Message-ID <OpenNMS/opennms/push/refs/heads/foundation-2024/[email protected]>
  Branch: refs/heads/foundation-2024
  Home:   https://github.com/OpenNMS/opennms
  Commit: 7877808196b98281f68c6770d32899d7cd1ebf72
      https://github.com/OpenNMS/opennms/commit/7877808196b98281f68c6770d32899d7cd1ebf72
  Author: Marshall Massengill <[email protected]>
  Date:   2026-09-01 (Tue, 01 Sep 2026)

  Changed paths:
    M opennms-dao/src/main/java/org/opennms/netmgt/dao/hibernate/HibernateCriteriaConverter.java
    M opennms-dao/src/test/java/org/opennms/netmgt/dao/hibernate/HibernateCriteriaConverterIT.java
    M opennms-webapp-rest/src/main/java/org/opennms/web/rest/v1/AlarmRestServiceBase.java
    M opennms-webapp-rest/src/main/java/org/opennms/web/rest/v1/AlarmStatsRestService.java

  Log Message:
  -----------
  NMS-20161: Apply criteria fetch modes after the distinct rewrite for v1 /rest/alarms  (#8762)

* NMS-20161: Apply criteria fetch modes after the distinct rewrite

HibernateCriteriaVisitor.visitFetch() set fetch modes directly on
m_criteria, but getCriteria() then implements distinct() by demoting that
criteria to an id-only subquery and building a new outer criteria. The
fetch modes went with the subquery, where Hibernate ignores them anyway
once a projection is set, so any criteria combining fetch(EAGER) with
distinct() silently got no join.

For v1 /rest/alarms this left OnmsAlarm.lastEvent as a lazy proxy read in
a separate statement per alarm, during hydration and after the alarm rows
had been read. An event deleted in that window by auto-clean reduction
raises ObjectNotFoundException, which OnmsAlarm.setLastEvent swallows, so
the broken proxy escapes the DAO and fails later inside the serializer,
truncating the response body.

Hold the fetch modes and apply them to the outer criteria after the
rewrite, the way m_orders already is.

* NMS-20161: Remove the unresolvable firstEvent fetch from the v1 alarm criteria

OnmsAlarm has no firstEvent property. Its only OnmsEvent association is
lastEvent; firstEventTime is a plain column. Hibernate ignores fetch modes
whose path it cannot resolve, so this threw nothing before and throws
nothing now, but the preceding commit makes these declarations reach the
query, and a live fetch mode that resolves to nothing is a trap for the
next reader.

* NMS-20161: Keep to-many fetches out of the distinct outer criteria

Applying the held fetch modes to the outer criteria makes them live for
every association, not just the to-one ones the alarm criteria needs. A
join fetch of a collection returns one outer row per element, which would
undo the distinct() rewrite it is applied after and leave setMaxResults
counting joined rows rather than entities. No caller fetches a collection
today, but the declaration now reaches the query, so the trap is real.

Ask the session factory whether the path is collection-valued and skip
those fetches, leaving the association to load the way it did when the
fetch modes still went to the subquery. Answering that needs a
SessionFactory, so the two entry points that take a Session hand theirs to
the visitor; the detached overloads, which nothing calls, still apply
every fetch mode.



To unsubscribe from these emails, change your notification settings at https://github.com/OpenNMS/opennms/settings/notifications


_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/wiki/index.php?page=MailingListFaq
opennms-cvs mailing list

To *unsubscribe* or change your subscription options, see the bottom of this page:
https://lists.sourceforge.net/lists/listinfo/opennms-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.