Why is the entity not saved?
zottel Sep 17, 2010 8:48 AMHi,
I have an entity that was fetched from the database for display in a rich:dataTable. It is linked to another entity of the same type.
If I change stuff in the current entity and its linked sibling, the changes to the current entity are saved to the database, but those to the linked entity are not. Why? I thought the linked entity must be managed by the entity manager, too? What do I have to do also update the linked entity?
Sample Code:
@Entity public class TextModule implements java.io.Serializable { [...] private Integer releaseState; private TextModule previousVersion; [...incl. getters and setters, of course...] } @Name("textModuleHome") @Scope(ScopeType.PAGE) public class TextModuleHome extends EntityHome<TextModule> { [...] public String release(TextModule textModule) { textModule.setReleaseState(ReleaseStateSet.RELEASED); if (textModule.getPreviousVersion() != null) { supersede(textModule.getPreviousVersion()); } return this.update(); } public String supersede(TextModule textModule) { textModule.setReleaseState(ReleaseStateSet.SUPERSEDED); return "superseded"; } [...] }
release(textModule) is called from a line of rich:dataTable with the TextModule that is displayed in the current line, using an a4j:commandButton (namespace is a: here, not a4j):
<rich:panel id="listOrText"> [...] <rich:dataTable id="textModuleList" var="_textModule" value="#{textModuleList.resultList}" rendered="#{not empty textModuleList.resultList}"> [...] <rich:column styleClass="action"> <f:facet name="header">Change State</f:facet> <a:commandButton action="#{textModuleHome.release(_textModule)}" value="Release" rendered="#{_textModule.releaseState == 1}" reRender="listOrText" /> [...] </rich:column> [...] </rich:dataTable> </rich:panel>
When I click the Release button, textModule gets changed and saved to the database as it should, but textModule.previousVersion is not saved to the database.
I thought the linked entities the entity manager fetches will automatically be managed, too? Why aren't those changes saved? What can I do to ensure they are saved?
Thanks,
Christian