Class JpaEntityVersionListener

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

    public class JpaEntityVersionListener
    extends Object
    implements org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreUpdateEventListener
    Listen on changes on child- and root entities and updates the current entity version of the root. This support a multiple level parent-child relationship, where all parents needs the entity version to be updated in case it was effectively changed. The traversing is stopped at that point when it is detected that parent entity version is the same one. It is based on an assumption that it may happen that one parent entity could be extracted into "parent A -> parent B -> child" format. Then the change (insertion, deletion or update) of the child should bump the entity version of both parent B and parent A.
    See Also:
    Serialized Form
    • Constructor Detail

      • JpaEntityVersionListener

        public JpaEntityVersionListener()
    • Method Detail

      • updateEntityVersion

        public void updateEntityVersion​(Object entity)
                                 throws org.hibernate.HibernateException
        Traverse from current entity through its parent tree and update the entity version of it. Stop if non-changed parent is found.
      • 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