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:42:32 GMT
Yes. It is my understanding the that Hibernate FlushMode MANUAL or NEVER 
(deprecated) instructs Hibernate to only flush the session when explitly 
instructed to do so. In my case, I assume this means on a call to 
EntityManager.flush(). 

By default, the mode seems to be set to AUTO. I've tried unsuccessfully, 
through the PersitenceProperty notation, via persistence.xml, and the 
jpaPropertyMap property of the spring 
LocalContainerEntityManagerFactoryBean to set the 
"org.hibernate.flushMode" property to "MANUAL". It was my hope that if I 
could instruct Hibernate to use a MANUAL flush mode, then it wouldn't 
flush upon session.close(). 

However, I've been unsuccessful in setting the flushMode thus far. I'm 
going to try rebuilding the hibernate-entitymanager-3.3.1GA package with 
the FlushMode set to MANUAL just to see if I can get the result I want.

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



"Musachy Barroso" <musachy@gmail.com> 
10/01/2007 08:21 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






Only difference is that I don't use model driven. Is there any setting
to tell hibernate to flush the session when closed or it does that by
default?

musachy

On 10/1/07, Jon_French@fws.gov <Jon_French@fws.gov> wrote:
> Yes, musachy. I do something very similar. Here is my prepare() method:
>
>     public void prepare() throws Exception {
>         if( this.id==0 ) {
>             this.entity = new Entity();
>         } else {
>             this.entity = this.entityDao.findById(this.id);
>         }
>     }
>
> Here is the (obvious) getModel():
>
>     public Object getModel() {
>         return this.entity;
>     }
>
> Here is the update, "execute()" method that is called upon form
> submission:
>
>     @Validations(
>            requiredStrings =
>                     {@RequiredStringValidator(fieldName = "model.name",
> message = "You must enter a title.")}
>     )
>     public String update() {
>         if( this.id==0 ) {
>             this.entityDao.create(this.entity);
>         } else {
>             this.entity.update(this.entity);
>         }
>         return SUCCESS;
>     }
>
> So when a user enters a blank "model.name" field, this.entity.name
> property gets set to null, the update() method never is called, but
> Hibernate tries to write the update to the database when
> OpenEntityManagerInViewFilter closes the EntityManager:
>
> Here is the relevant code from OpenEntityManagerInViewFilter
>
>       protected void doFilterInternal(
>                         HttpServletRequest request, HttpServletResponse
> response, FilterChain filterChain)
>                         throws ServletException, IOException {
>
>               ...
>
>                 try {
>                         filterChain.doFilter(request, response);
>                 }
>
>                 finally {
>                         if (!participate) {
>                                 EntityManagerHolder emHolder =
> (EntityManagerHolder)
>  TransactionSynchronizationManager.unbindResource(emf);
>                                 emHolder.getEntityManager().close();
>                         }
>                 }
>         }
>
> 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
>
>
>
> "Musachy Barroso" <musachy@gmail.com>
> 10/01/2007 05:10 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
>
>
>
>
>
>
> I only use the beanutils.copy solution on a few places, on the other
> cases I always load the object model on the prepare() method if the
> "id" field is set (editing), and then call update or create on the
> entity manager in my action method. I never got that problem so I'm
> wondering what is different. (I use JPA on top of hibernate)
>
> musachy
>
> On 10/1/07, Dave Newton <newton.dave@yahoo.com> wrote:
> > --- Jon_French@fws.gov wrote:
> > > That's an interesting idea Dave. I'm using the
> > > paramsPrepareStack. It'll take some investigation to
> >
> > > see if that would fix the issue.
> >
> > Shouldn't take much; it might be as simple as adding a
> > validate/defaultWorkFlow up towards the top (although
> > I might try just adding new ones rather than removing
> > the existing ones).
> >
> > > Fort Collins Science Center
> > > US Geological Survey
> > > 2150 Centre Ave, Building C
> >
> > I used to live up Poudre River Canyon (Poudre Park); I
> > sure miss the climbing out there :(
> >
> > d.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
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