对于 Java EE,我需要使用有状态会话 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;
}
}
但是每次我输入我的bean时,connections
变量都设置为0。
我不知道在哪里可以搜索解决方案。