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

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

    Hi.

    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-config.xml:

    Code:
    	<webflow:flow-executor id="flowExecutor">
    		<webflow:flow-execution-listeners>
    			<webflow:listener ref="facesContextListener" />
    			<webflow:listener ref="jpaFlowExecutionListener"/>
    		</webflow:flow-execution-listeners>
    	</webflow:flow-executor>
    
    	<bean id="jpaFlowExecutionListener"
    		class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
    		<constructor-arg ref="entityManagerFactory" />
    		<constructor-arg ref="transactionManager" />
    	</bean>
    crud-flow.xml:

    Code:
            <persistence-context />
    
    	<view-state id="view">
    		<transition on="back" to="list" />
    	</view-state>
    
            <view-state id="list">
    		<transition on="delete" to="list" />
    		<transition on="edit" to="edit">
    			<set name="flowScope.xpto" value="selectedXptoToEdit" />
    		</transition>
    		<transition on="create" to="edit">
    			<set name="flowScope.xpto" value="xptoFlowService.createEntity()" />
    		</transition>
    	</view-state>
    
    	<view-state id="edit" model="xpto">
    		<transition on="back" to="cancelEdit" bind="false" validate="false" />
    		<transition on="save" to="list">
    			<evaluate expression="xptoFlowService.save(xpto)" />
    		</transition>
    	</view-state>	
    	
    	<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
Working...
X