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 ?model.name? property is 
non-null. The validation works perfectly.
However, during Struts Interceptor processing of a user entered empty 
string for the ?model.name? 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:
http://forums.opensymphony.com/thread.jspa?messageID=5315&#5315
(which seems to be the exact same problem except with the 
OpenSessionInView filter instead of my OpenEntityManagerInView filter) 
And this spring post:
http://forum.springframework.org/showthread.php?t=35740
 ? 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
Programmer
ASRC Management Services
ECOS Development Team
[EMAIL PROTECTED]
970-226-9290

Fort Collins Science Center
US Geological Survey
2150 Centre Ave, Building C
Fort Collins, CO 80526-8116

Reply via email to