[
http://jira.jboss.com/jira/browse/JBSEAM-369?page=all ]
Christian Bauer reopened JBSEAM-369:
------------------------------------
This prints out FlushMode.AUTO instead of FlushMode.MANUAL:
package auction.beans;
import org.jboss.seam.annotations.*;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import org.jboss.seam.ScopeType;
import org.hibernate.ejb.HibernateEntityManager;
import javax.ejb.Stateful;
import javax.ejb.Remove;
import javax.persistence.EntityManager;
import auction.model.Category;
import auction.model.Item;
import auction.dao.CategoryDAO;
import auction.interceptors.LoggedIn;
import java.util.*;
/**
* A conversational component for browsing the catalog.
*
* When the first variable for "catalog" has to be resolved, this component is
* instantiated and a conversation begins. All root categories (with no parent)
* of the catalog are loaded immediately and held during the conversation.
*
* When a category is selected, the selected value is passed into the method
* setSelectedCategory(category) manually, this is the easiest way to get the
* value of a click from a Trinidad tree JSF component.
*
* The item list is loaded when a category is selected and outjected into a
* data model for display. When a user triggers an action in the data model's
* table, the selectedItem of this conversation is set.
*
* The conversation ends usually by timeout or when it is destroyed
* with one of Seams UI conversation management switchers/lists.
*
* @author Christian Bauer
*/
@Name("catalog")
@Scope(ScopeType.CONVERSATION) // Redundant, a SFSB is default in conversation context
@LoggedIn // Wrap LoginInterceptor around every method call
@Stateful
public class CatalogBean implements Catalog {
// We don't call the EntityManager directly in this bean (except to flush), only
the DAOs.
// But the DAOs are not always called in every method that does data access. For
example,
// when setSelectedCategory() is called, the categoryDAO is injected into this bean,
// but the persistence context is not set on the categoryDAO (because no method is
// called on the DAO, we just load a collection on-demand). So the persistence
context
// doesn't join the JTA transaction, which means it doesn't get flushed when
// setSelectedCategory() returns (no synchronization registered). Short story: The
// persistence context needs to be injected managed here, so that lazy loading works
// properly in all methods of this stateful bean.
@In(value = "caveatEmptorEM", create = true)
private EntityManager em;
// A stateless (yes, even for them create="true" is required) DAO component
injected by Seam
@In(create = true)
private CategoryDAO categoryDAO;
// This bean holds the root categories during a conversation
private List<Category> rootCategories;
// If present, Seam outjects this into the 'currentCategory' CONVERSATION
variable
@In(required = false)
@Out(required = false, scope = ScopeType.CONVERSATION)
private Category currentCategory;
// Seam outjects this always to the 'itemList" CONVERSATION variable as a JSF
DataModel
@DataModel
private List<Item> itemList;
/**
* Seam calls this when the Catalog bean is instantiated for a particular
CONVERSATION.
* Seam will start a long-running conversation when this method is called.
*/
@Create
@Begin(flushMode = FlushModeType.MANUAL)
public void refreshRootCategories() {
System.out.println("################### FLUSHMODE" +
((HibernateEntityManager)em).getSession().getFlushMode());
rootCategories = categoryDAO.findAll(true);
}
public List<Category> getRootCategories() {
return rootCategories;
}
/**
* Loads the selected category's items into a data model that is then outjected.
* @param selectedCategory
*/
public void setSelectedCategory(Category selectedCategory) {
// Prepare the member variable for outjection
currentCategory = selectedCategory;
// Refresh the itemList (wrap the Set in a List, no pre-defined or database
sorting)
itemList = new ArrayList<Item>(currentCategory.getItems());
}
@Remove @Destroy @End
public void closeCatalog() {
// Nothing to do here, Seam will close the managed persistence context when
// this method returns.
}
}
@Create and @Begin(FlushModeType.MANUAL) execute in wrong order
---------------------------------------------------------------
Key: JBSEAM-369
URL:
http://jira.jboss.com/jira/browse/JBSEAM-369
Project: JBoss Seam
Issue Type: Bug
Components: Core
Reporter: Christian Bauer
Assigned To: Gavin King
Priority: Blocker
Fix For: 1.1
This is CVS HEAD:
@Name("catalog")
@Stateful
public class CatalogBean implements Catalog {
@In(value = "caveatEmptorEM", create = true)
private EntityManager em;
@Create
@Begin(flushMode = FlushModeType.MANUAL)
public void refreshRootCategories() {
...
}
The EntityManager is in FlushMode.AUTO because it is injected before the
ConversationInterceptor runs and reads the @Begin annotation.
So ManagedPersistenceContext.create() runs and sets the flush mode before the
setFlushMode() method on the Conversation component is called.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira