Transaction Rollback with EJB 2.1

0

I need to know how to do a rollback of the actions created in an EJB transaction, I have already researched and everything I try does not work!

Follow the code!

/**
 * @ejb.bean name="WebServiceFacade" jndi-name="WebServiceFacadeBean" type="Stateful"
 * @ejb.ejb-external-ref ref-name="ejb/WebServiceLocal" link="Evento" type="Session" view-type="local"
 *                       home="br.com.syonet.collaborativeAccess.crm.evento.ejb.WebServiceLocalHome"
 *                       business="br.com.syonet.collaborativeAccess.crm.evento.ejb.WebServiceLocal"
 * @since 17/12/2015
 */
public abstract class WebServiceFacadeBean implements SessionBean {

    private final Logger logger = ThreadLogger.getNewInstance();
    private CRMLocal crm;
    private PersistenciaLocal persistencia;
    protected SessionContext ctx;

    public WebServiceFacadeBean() {
        try {
            crm = CRMUtil.getLocalHome().create();
            persistencia = PersistenciaUtil.getLocalHome().create();
        } catch ( Exception e ) {
            // trolll
        }
    }

    /**
     * Sets the session context
     *
     * @param javax.ejb.SessionContext
     *            the new ctx value
     */
    public void setSessionContext(javax.ejb.SessionContext ctx) {
        this.ctx = ctx;
    }

    /**
     * Unsets the session context
     *
     * @param javax.ejb.SessionContext
     *            ctx value
     */
    public void unsetSessionContext() {
        this.ctx = null;
    }

    /**
     * @ejb.create-method tview-type="local"
     */
    public void ejbCreate() throws javax.ejb.CreateException {
    }

    /**
     * @throws SystemException 
     * @throws NotSupportedException 
     * @ejb:interface-method tview-type="local"
     * @ejb.transaction type="RequiresNew"
     */
    public void testeRollback() throws NotSupportedException, SystemException{
        ComentarioValue comentario = new ComentarioValue();
        comentario.setDataAlt( System.currentTimeMillis() );
        comentario.setDataInc( System.currentTimeMillis() );
        comentario.setIdEvento( 969745 );
        comentario.setTexto( "texto" );
        comentario.setUsuarioAlt( "MASTER" );
        comentario.setUsuarioInc( "MASTER" );
        try {
            ComentarioUtil.getLocalHome().create( comentario );
        } catch ( CreateException e ) {
        } catch ( NamingException e ) {
        }
        //Queria forçar o rollback da transação nesse momento, apenas para teste.
        ctx.setRollbackOnly();
    }
}

For separate viewing only, this is the method.

     /**
     * @throws SystemException 
     * @throws NotSupportedException 
     * @ejb:interface-method tview-type="local"
     * @ejb.transaction type="RequiresNew"
     */
    public void testeRollback() throws NotSupportedException, SystemException{
        ComentarioValue comentario = new ComentarioValue();
        comentario.setDataAlt( System.currentTimeMillis() );
        comentario.setDataInc( System.currentTimeMillis() );
        comentario.setIdEvento( 969745 );
        comentario.setTexto( "texto" );
        comentario.setUsuarioAlt( "MASTER" );
        comentario.setUsuarioInc( "MASTER" );
        try {
            ComentarioUtil.getLocalHome().create( comentario );
        } catch ( CreateException e ) {
        } catch ( NamingException e ) {
        }
        //Queria forçar o rollback da transação nesse momento, apenas para teste.
        ctx.setRollbackOnly();
    }

So the question remains, how can I do a rollback with EJB 2.1?

Technologies: EJB 2.1 Java 7 xDoclet

    
asked by anonymous 18.12.2015 / 16:37

0 answers