Announcement Announcement Module
Collapse
No announcement yet.
IllegalStateException when persisting a record that violates a unique constraint Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalStateException when persisting a record that violates a unique constraint

    Hello all,

    I am using Spring Web Flow 2.3.2.

    I am trying to add exception handling for when a user tries to enter a value that conflicts with a unique constraint in the database. Below is a snippet from my flow XML:

    HTML Code:
    <view-state id="editCriteria" view="editCriteria" model="criteria">
    	<transition on="saveReturn" to="endSaveReturn">
    		<evaluate expression="criteriaService.persistTx(criteria)"/>
    	</transition>
    	<transition on="cancel" to="endCancel"/>
    	<exception-handler bean="commitExceptionHandler"/>
    </view-state>

    I am able to catch the DataIntegrityExceptionViolation using the specified custom exception handler and re-render the page with the appropriate error message. However, I get this IllegalStateException that I cannot catch:

    Code:
    java.lang.IllegalStateException: Cannot serialize a session while connected
    	at org.hibernate.internal.SessionImpl.writeObject(SessionImpl.java:2117)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at java.util.HashMap.writeObject(HashMap.java:1014)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    	at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
    	at org.springframework.webflow.core.collection.LocalAttributeMap.writeObject(LocalAttributeMap.java:327)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at org.springframework.webflow.engine.impl.FlowSessionImpl.writeExternal(FlowSessionImpl.java:160)
    	at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1443)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1414)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at java.util.LinkedList.writeObject(LinkedList.java:1118)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.writeExternal(FlowExecutionImpl.java:309)
    	at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1443)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1414)
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.serialize(SerializedFlowExecutionSnapshot.java:173)
    	at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.<init>(SerializedFlowExecutionSnapshot.java:70)
    	at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.createSnapshot(SerializedFlowExecutionSnapshotFactory.java:70)
    	at org.springframework.webflow.execution.repository.snapshot.AbstractSnapshottingFlowExecutionRepository.snapshot(AbstractSnapshottingFlowExecutionRepository.java:75)
    	at org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.putFlowExecution(DefaultFlowExecutionRepository.java:126)
    	at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:171)
    	at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
    While the page is re-rendered with the error message, when I then try to re-submit using a valid value the page simply re-renders. When I hit submit again the flow resumes execution and I can persist the valid value. I'm trying to catch or avoid the IllegalStateException as I'm sure that's what's causing this behavior.

    Does anyone have any ideas? Is there a better way handle DataIntegrityViolationExceptions in a flow?

  • #2
    I've had to fall back to pure Spring Web MVC. The IllegalStateException does not occur and I am able to catch the DataIntegrityViolationException and re-render the form without issue. Looking at the stack trace, it seems the error occurs when Web Flow tries to create a snapshot after the transition completes. This seems like a bug and not user error to me, especially since MVC handles the same situation fine, and could be fixed in future versions.

    Comment

    Working...
    X