Update alarm via Plugin

Hi,

I’m writing a plugin to enrich alarm with attributes which I get from REST api.
I have a problem with using alarmDao.
I inject it in my class and can use get() without problems.
However trying to call save/update throws exception:

2019-09-12T07:45:53,363 | ERROR | qtp860682118-105361 | ErrorResponseProvider | 252 - org.opennms.features.rest-provider - 24.1.1 | An exception occurred while processing a rest request in an OSGi Rest Service: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition.
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition.
at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1270) ~[?:?]
at org.springframework.orm.hibernate3.HibernateTemplate$14.doInHibernate(HibernateTemplate.java:747) ~[?:?]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:410) ~[?:?]
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:378) ~[?:?]
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:744) ~[?:?]
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:739) ~[?:?]
at org.opennms.netmgt.dao.hibernate.AbstractDaoHibernate.update(AbstractDaoHibernate.java:406) ~[?:?]
at Proxy9aae7106_e96a_4ca0_aa46_373e715fe71b.update(Unknown Source) ~[?:?]

I use @Transactional annotation with propagation = Propagation.REQUIRED, readOnly = false.
Any suggestion would be appreciated.

So I managed to solve it while looking at other implementation like AlarmDaoImpl or UserDefinedLinkDaoImpl.
I injected sessionUtils to my class and then called:

    sessionUtils.withTransaction(() -> {
        alarmDao.update(alarm);
        return null;});

It works. :slight_smile:

1 Like