Created
June 1, 2010 15:44
-
-
Save dbonillaf/421069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.six.test; | |
import javax.persistence.EntityManager; | |
import com.six.model.entity.*; | |
import javax.ejb.Stateless; | |
import javax.ejb.TransactionAttribute; | |
import javax.ejb.TransactionAttributeType; | |
import javax.persistence.PersistenceContext; | |
/** | |
* @author Hulk | |
*/ | |
@Stateless | |
@TransactionAttribute(TransactionAttributeType.REQUIRED) | |
public class NOActualizaCliente { | |
@PersistenceContext | |
private EntityManager em; | |
public NOActualizaCliente() { | |
} | |
/** | |
* Este método sirve para comprobar que las transacciones | |
* funcionan con llamadas a varios métodos puesto que hasta que el método | |
* que la invoca no hace el flush, los cambios no llegan a Base de Datos | |
* @param c un Cliente de toda la vida | |
*/ | |
@TransactionAttribute(TransactionAttributeType.MANDATORY) | |
public void renombra(Customer c) { | |
try { | |
c.setName("Esto JAMÁS deberia ir a base de datos"); | |
em.persist(c); | |
em.flush(); | |
System.out.println("El nombre del Cliente es: " + c.getName()); | |
} catch (Throwable e) { | |
System.out.println("ERROR: " + e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment