You can try 2 options:

1. Use validation by name to prevent name changes before request to DB. It
will be executed before name property will be assigned to new value:

@OnEvent(value=EventConstants.VALIDATE_FORM, component="nameField")
public void validateName() {
   //...
}

<t:beaneditform t:id="user" submitlabel="message:create-user">
  <p:name>
    <t:label for="nameField"/>
    <t:textfield t:id="nameField" value="user.name"/>
  </p:name>
</t:beaneditform>

2. Retrieve profile in separate transaction with uncommited read isolation.


On Fri, Nov 16, 2012 at 5:15 PM, Nicolas Barrera <nbarr...@gmail.com> wrote:

> Hi all,
>
> I 'm not using the tapestry-hibernate module.
>
> I 'm using spring configured hibernate, tapestry-spring, and an open
> session in view spring filter.
>
> I can use BeanEditForm to create a new entity and save it, the problem is
> when trying to modify an existing entity.
>
> My problem is that during activation after submission I get an unmodified
> instance of the entity from the database,
> after that the beaneditform modifies the properties of that entity and
> during validation when the DAO performs a criteria query
> by name changes on the entity object are being flushed to the database.
>
> I wonder how does the tapestry-hibernate module handles these  kind of
> trouble,
>
> Here is my code:
>
>     @OnEvent(value=EventConstants.ACTIVATE)
> >     public void activate(Long profileId) {
> >         profile = this.profileDAO.load(profileId);
> >     }
> >
> >     @OnEvent(value=EventConstants.PASSIVATE)
> >     public Long passivate() {
> >         return this.profile.getId();
> >     }
> >
> >     @Log
> >     @OnEvent(value=EventConstants.VALIDATE_FORM)
> >     public void validate() {
> >         try {
> >             // validating if the new name already exists, if it does fail
> > validation
> >             this.profileDAO.getByName(profile.getName());
> >
> >
> this.profileForm.recordError(messages.get("error.profile.already.exists"));
> >         } catch(ModelException me) {
> >             // validation is expecting this exception, I know it's nasty
> > but...
> >         }
> >
> >     }
> >
> >     @OnEvent(value=EventConstants.SUCCESS)
> >     public Object persistNewUser() throws ModelException {
> >         this.profileDAO.save(profile);
> >         return ListProfiles.class;
> >     }
> >
>
> tried evicting the instance from the session on prepareForSubmit but then
> (as the entity is lazy) beaneditform fails trying to set the properties.
>
> Right now I 'll avoid using beaneditform for modification pages but I 'd
> definitely prefer using it!
>
> thank you so much,
>
> cheers
>
> Nicolás.-
>



-- 
BR
Ivan

Reply via email to