Class JpaOptimisticLockingListener

  • All Implemented Interfaces:
    Serializable, org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreUpdateEventListener

    public class JpaOptimisticLockingListener
    extends Object
    implements org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreUpdateEventListener
    Listen on changes on child entities and forces an optimistic locking increment on the topmost parent aka root. This support a multiple level parent-child relationship, where only the upmost parent is locked.
    See Also:
    Serialized Form
    • Constructor Detail

      • JpaOptimisticLockingListener

        public JpaOptimisticLockingListener()
    • Method Detail

      • lockRootEntity

        public void lockRootEntity​(org.hibernate.Session session,
                                   Object entity)
                            throws org.hibernate.HibernateException
        Check if the entity is a child with a parent and force optimistic locking increment on the upmost parent aka root.
        Throws:
        org.hibernate.HibernateException
      • onPreInsert

        public boolean onPreInsert​(org.hibernate.event.spi.PreInsertEvent event)
        Specified by:
        onPreInsert in interface org.hibernate.event.spi.PreInsertEventListener
      • onPreDelete

        public boolean onPreDelete​(org.hibernate.event.spi.PreDeleteEvent event)
        Specified by:
        onPreDelete in interface org.hibernate.event.spi.PreDeleteEventListener
      • onPreUpdate

        public boolean onPreUpdate​(org.hibernate.event.spi.PreUpdateEvent event)
        Specified by:
        onPreUpdate in interface org.hibernate.event.spi.PreUpdateEventListener