struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject ModelDriven CRUD validation failure still causes JPA update
Date Mon, 01 Oct 2007 20:31:10 GMT
I have a ModelDriven action which controls CRUD operations on JPA managed 
Entity E. E has a property called ?name? which maps to a database column 
with a NOT NULL constraint. I have added a RequiredStringValidator 
annotation to my Action to validate that the ? property is 
non-null. The validation works perfectly.
However, during Struts Interceptor processing of a user entered empty 
string for the ? ServletRequest parameter, entity instance E 
has its getName() property set to a null value. Hibernate (my JPA 
implementation provider) detects this property state change when the 
Hibernate session is flushed at the closing of the JPA EntityManager by 
the configured OpenEntityManagerInView ServletFilter. This results in an 
attempt by Hibernate to update the ?name? database column to null and 
results in a SqlException. 
So the problem is that even with appropriate validation on a ModelDriven 
action, my Entity moves to an invalid state which Hibernate then tries to 
persist to the database at the closing of the session. 
Based on what I gleaned from this WebWorkx post:
(which seems to be the exact same problem except with the 
OpenSessionInView filter instead of my OpenEntityManagerInView filter) 
And this spring post:
 ? I think that what I need to do is set Hibernate?s flush mode to NEVER. 
What this means to me is that Hibernate will only flush when I execute a 
EntityManager.flush() command and that OpenEntityManagerInView?s closing 
of the EntityManager won?t automatically result in a Hibernate session 
flush and thus Entity E?s invalid state will not be persisted. This is in 
line with what I understand to be the default behavior of Spring?s 
OpenSessionInView filter. Unfortunately, I have not yet been able to set 
Hibernate's flush mode (nor am I certain that this will solve my issue).
Can anyone shed some light on this problem?
Thanks in advance!

Jon French
ASRC Management Services
ECOS Development Team

Fort Collins Science Center
US Geological Survey
2150 Centre Ave, Building C
Fort Collins, CO 80526-8116
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message