FlushMode of EntityManager
tienlantri Sep 28, 2010 5:38 AMI have an abstract action who defines the conversation (start and end)
@AutoCreate
@Scope(ScopeType.CONVERSATION)
public abstract class MainAction {
@In
private EntityManager entityManager;
@Create
public void initComponent() {
createConversation();
logger.info("createAction");
init();
}
private void createConversation() {
Conversation.instance().begin();
Conversation.instance().changeFlushMode(FlushModeType.MANUAL);
}
public void save() {
logger.info("Commiting transaction");
entityManager.flush();
logger.info("Transaction commited");
FacesMessages.instance().addFromResourceBundle(Severity.INFO,
"general.saveMessage");
endConversation();
createConversation();
}
private void endConversation() {
Conversation.instance().end(false);
}
public abstract void init();
/**
* Getteur de l'attribut entityManager.
*
* @return EntityManager la valeur de entityManager
*/
public EntityManager getEntityManager() {
return entityManager;
}
}
All the actions for each screen extends from MainAction.
Eventhough in MainAction I start CONVERSATION with FlushMode type MANUAL, in each action (extends MainAction) I receive Flush type is null (Note that in GestionPrestActAction who extends MainAction, I retrieve EntityManager by using getEntityManager in MainAction). I don't understand why. And that's also the reason why when I modify something, the modification is committed directly to DB without waiting for entityManager.flush()
Here is the code of an action extends MainAction
@AutoCreate
@Scope(ScopeType.CONVERSATION)
@Name("gestionPrestAct")
public class GestionPrestActAction extends MainAction {
@Logger
private Log logger;
@Override
public void init() {
activiteToModif = new Activite();
allActivites = activiteService.getAllActivites();
initDataModel();
}
@SuppressWarnings("unchecked")
@Factory(autoCreate = true, value = "prestationsAll")
public void initDataModel() {
logger.info("initDataModel");
prestationsAll = prestationService.getAllPrestations();
Collections.sort(prestationsAll, new Prestation.PrestationComparator());
logger.info("Flush mode type " + getEntityManager().getFlushMode());
}
}
Is there someone who could tell me the reason?
Thanks
Tina
@AutoCreate
@Scope(ScopeType.CONVERSATION)
public abstract class MainAction {
@In
private EntityManager entityManager;
@Create
public void initComponent() {
createConversation();
logger.info("createAction");
init();
}
private void createConversation() {
Conversation.instance().begin();
Conversation.instance().changeFlushMode(FlushModeType.MANUAL);
}
public void save() {
logger.info("Commiting transaction");
entityManager.flush();
logger.info("Transaction commited");
FacesMessages.instance().addFromResourceBundle(Severity.INFO,
"general.saveMessage");
endConversation();
createConversation();
}
private void endConversation() {
Conversation.instance().end(false);
}
public abstract void init();
/**
* Getteur de l'attribut entityManager.
*
* @return EntityManager la valeur de entityManager
*/
public EntityManager getEntityManager() {
return entityManager;
}
}
All the actions for each screen extends from MainAction.
Eventhough in MainAction I start CONVERSATION with FlushMode type MANUAL, in each action (extends MainAction) I receive Flush type is null (Note that in GestionPrestActAction who extends MainAction, I retrieve EntityManager by using getEntityManager in MainAction). I don't understand why. And that's also the reason why when I modify something, the modification is committed directly to DB without waiting for entityManager.flush()
Here is the code of an action extends MainAction
@AutoCreate
@Scope(ScopeType.CONVERSATION)
@Name("gestionPrestAct")
public class GestionPrestActAction extends MainAction {
@Logger
private Log logger;
@Override
public void init() {
activiteToModif = new Activite();
allActivites = activiteService.getAllActivites();
initDataModel();
}
@SuppressWarnings("unchecked")
@Factory(autoCreate = true, value = "prestationsAll")
public void initDataModel() {
logger.info("initDataModel");
prestationsAll = prestationService.getAllPrestations();
Collections.sort(prestationsAll, new Prestation.PrestationComparator());
logger.info("Flush mode type " + getEntityManager().getFlushMode());
}
}
Is there someone who could tell me the reason?
Thanks
Tina