With Java EE I need to use a stateful session Bean.
@Stateful
@TransactionManagement(TransactionManagementType.BEAN)
public class FacadeExercice extends AbstractFacade<EntityBeanExercice>
implements IFacadeExercice {
@PersistenceContext(unitName = "GestionCours-ejbPU")
private EntityManager em;
@Resource
private UserTransaction transaction;
private int lastChange;
private int connections;
[...]
@Override
public EntityBeanExercice find(Object id) {
EntityBeanExercice ex = null;
connections += 5;
try {
transaction.begin();
ex = super.find(id);
lastChange = ex.getLastChange();
transaction.commit();
} catch (Exception ex1) {
Logger.getLogger(FacadeExercice.class.getName()).log(
Level.SEVERE, null, ex1);
}
return ex;
}
}
But every time I enter in my bean, the connections
variable is set to 0.
I have no Idea where I can search a solution.