Announcement Announcement Module
No announcement yet.
Jpa Persistence: Model is being persisted on every view state! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jpa Persistence: Model is being persisted on every view state!


    I'm trying to create a CRUD flow, however i'm having problems with the edit form of a model, since it's persisting the model object on every interaction, even on validation errors.

    Here is my setup:


    	<webflow:flow-executor id="flowExecutor">
    			<webflow:listener ref="facesContextListener" />
    			<webflow:listener ref="jpaFlowExecutionListener"/>
    	<bean id="jpaFlowExecutionListener"
    		<constructor-arg ref="entityManagerFactory" />
    		<constructor-arg ref="transactionManager" />

            <persistence-context />
    	<view-state id="view">
    		<transition on="back" to="list" />
            <view-state id="list">
    		<transition on="delete" to="list" />
    		<transition on="edit" to="edit">
    			<set name="flowScope.xpto" value="selectedXptoToEdit" />
    		<transition on="create" to="edit">
    			<set name="flowScope.xpto" value="xptoFlowService.createEntity()" />
    	<view-state id="edit" model="xpto">
    		<transition on="back" to="cancelEdit" bind="false" validate="false" />
    		<transition on="save" to="list">
    			<evaluate expression="" />
    	<end-state id="cancelEdit" commit="false" />
    The problem is, if you try to edit a Model entity, change fields values, the try to save and a validation error occurs, and then try to cancel, the model is already persisted on db. Or if you have a confirmation dialog before the save, when arriving to that view state the model is already persisted on db! I was on the impression that all the model changes made during the flow would only be persisted at the end of the flow.

    Can any one help me to figure out why do i have this behavior?

    Thanks in advance.

    Best regards