Class OpenEntityManagerInViewListener

  • All Implemented Interfaces:
    ExecutionCleanup, ExecutionInit

    public class OpenEntityManagerInViewListener
    extends java.lang.Object
    implements ExecutionCleanup, ExecutionInit
    Listener to init and cleanup the JPA entityManager automatically

    In WEB-INF/zk.xml, add following lines:

    
            <listener>
                    <description>Hibernate "OpenEntityManagerInView" Listener</description>
                    <listener-class>org.zkoss.zkplus.jpa.OpenEntityManagerInViewListener</listener-class>
            </listener>
     

    Applicable to EJB version 3.2.ga or later

    Since:
    3.0.2
    Author:
    Jeff
    • Constructor Detail

      • OpenEntityManagerInViewListener

        public OpenEntityManagerInViewListener()
    • Method Detail

      • cleanup

        public void cleanup​(Execution exec,
                            Execution parent,
                            java.util.List errs)
                     throws java.lang.Exception
        Description copied from interface: ExecutionCleanup
        called when an execution is about to be destroyed.

        If this method throws an exception, the stack trace will be logged, and the error message will be displayed at the client.

        When this method is invoked, the execution is still activated, so you can create components here.

        Specified by:
        cleanup in interface ExecutionCleanup
        Parameters:
        exec - the execution to clean up.
        parent - the previous execution, or null if no previous at all
        errs - a list of exceptions (java.lang.Throwable) if any exception occurred before this method is called, or null if no exception at all. Note: you can manipulate the list directly to add or clean up exceptions. For example, if exceptions are fixed correctly, you can call errs.clear() such that no error message will be displayed at the client.
        Throws:
        java.lang.Exception
      • handleException

        protected void handleException​(Execution exec,
                                       java.lang.Throwable ex)

        Default exception handler. This implementation simply rollback the transaction.

        Application developer might want to extends this class and override this method to do other things like compensate for any permanent changes during the conversation, and finally restart business conversation... what can be done here depends on the applications design.

        Parameters:
        exec - the execution to clean up.
        ex - the Throwable which is not handled during the execution