conversation state affects retrieval of entities - possible bug
x490812 Mar 3, 2009 7:29 PMI wish to list entities in a table ,then perform crud ops on the list. I am using an entityhome object to manage my entities. Here is my entity with the pertinent code...
@Entity @SequenceGenerator(name = "TBLREQUESTS_SEQ", sequenceName = "TBLREQUESTS_SEQ", allocationSize = 1) public class Tblrequests implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TBLREQUESTS_SEQ") private long id; . . @OneToOne @JoinColumn(name="PAYEECODE", referencedColumnName="PAYEE_CODE", insertable=false, updatable=false) private PayeeCodes payeeCodes; . .
1) main page displays a table of items and has an add button. The table gets the list from this function
public List<Tblrequests> getStuff() { EntityManager em = this.getEntityManager(); List<Tblrequests> l = em.createQuery("from Tblrequests").getResultList(); return l; }
2) I click add button - the action is /wizard.xhtml
. I clearInstance() before I get there, so that when I get there a new instance will be created. In pages.xml I start a new conversation via a begin conversation
<page view-id="/wizard.xhtml"> <param name="adjReqID" value="#{adjustmentRequest.id}" converterId="javax.faces.Long" /> <begin-conversation join="true" /> </page>
3) I go through the wizard and save the item - which calls an overriden persist on my entityhome new instance
public String persist() { assignUser(); setCreatedMessage(createValueExpression("successfully " + (isManaged()?"edited":"added") + " Request for loan " + getInstance().getLoannumber())); super.persist(); return "home"; }
4) In pages.xml, the return value from persist triggers a return to the main page, where I want to display the list of items, refreshed with the new item
<page . . <rule if-outcome="home"> <end-conversation /> <redirect view-id="/main.xhtml" /> </rule>
HOWEVER, when I get back to the main page, the list returned from the getStuff() function above holds all the original entities, but the new entity I just created is in the list, but not completely populated; The onetoone relationships are not retrieved. Yet, onetoone relationships should be eagerly loaded, and hacking the query to eagerly load has no affect
What I found is that if I put before-redirect in the end conversation above, then when I return to the main page, the list of entities is completely populated, but I lose my conversation and my faces messages because the conversation is ended before I return to the main page.
Why does the ending of the conversation affect the retrieval of the entities?
How can I keep the conversation until I leave the main page so that I can retain my facesmessages? I thought that was the purpose of a conversation