struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon_Fre...@fws.gov
Subject Re: ModelDriven CRUD validation failure still causes JPA update
Date Tue, 02 Oct 2007 02:05:32 GMT
Thanks Piero:

* don't flush the session and destroy the object

This is exactly what I want to do. However, the Hibernate session 
automatically flushes when the EntityManager is closed during the 
OpenEntityManagerInView filter exit filter operation. I definitely need 
the filter in place to lazy load collections in my view pages.

* instantiate a temporary bean used for the form only:
BeanUtils.copyProperties(tempBean, yourBean);

Yes, but I'm reluctant to use this work-around although I admit that it 
would probably work. IMO, the beauty of the ModelDriven pattern is that 
you don't have to do this copy but can rather cut out the old Struts 1 
ActionForm "middle-man" bean and do direct updates to your business 
objects. Everything works great except this one problem with a validation 
failure inappropriately triggering a database update.

* manage your entities with JPA's EntityManager, merge them manually.

I do. In fact, if the validation does NOT fail, my ModelDriven action 
calls a JPA backed DAO that does update the entity with a 
EntityManager.merge(...) call. In the case of failed validation, this DAO 
is never invoked, but rather Hibernate automatically "merges" the invalid 
Entity changes to the database when the Hibernate Session is closed.

Thanks for you help,

Jon French
Programmer
ASRC Management Services
ECOS Development Team
jon_french@fws.gov
970-226-9290

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



Piero Sartini <lists@pierosartini.de> 
10/01/2007 03:38 PM
Please respond to
"Struts Users Mailing List" <user@struts.apache.org>


To
"Struts Users Mailing List" <user@struts.apache.org>
cc

Subject
Re: ModelDriven CRUD validation failure still causes JPA update






> Since my Model is acquired from the Hibernate session (during the
> "prepare()" Action method), it is a transactional persistent instance.
> Note this from the hibernate documentation:
>
> "Transactional persistent instances (ie. objects loaded, saved, created 
or
> queried by the Session) may be manipulated by the application and any
> changes to persistent state will be persisted when the Session  is 
flushed
> (discussed later in this chapter). There is no need to call a particular
> method (like update(), which has a different purpose) to make your
> modifications persistent."

I do not know hibernate but you could try the following solutions:

* don't flush the session and destroy the object

* instantiate a temporary bean used for the form only:
BeanUtils.copyProperties(tempBean, yourBean);

* manage your entities with JPA's EntityManager, merge them manually.

Piero

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message