package ejb.contran5.acc;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


@Stateless
//@Stateless(mappedName="java:comp/env/ejb/constandby/ejbrem/SendingSession")
public class SendingSessionAccBean5 implements SendingSessionAcc5{

	@PersistenceContext(unitName="pu1")
	private EntityManager em;
	
/*	 EntityManagerFactory factory =
         Persistence.createEntityManagerFactory("pu1");
      EntityManager em = factory.createEntityManager( );*/

	

	
	//@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public void createEntity(){
		TranEntityAcc5 data = new TranEntityAcc5();
		//data.setId(1);
		data.setName("Previous Data");
		em.persist(data);
	}
	
	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public void updateEntityWithSleep(String name) {
	
		TranEntityAcc5 data = null;
		data = em.find(TranEntityAcc5.class, 1);
		data.setName(name);
		em.merge(data);

		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	public TranEntityAcc5 getEntity() {
	
		TranEntityAcc5 data = null;
		data = em.find(TranEntityAcc5.class, 1);
		
		return data;
	}


}