Hi Matej,

what about entities with lazy loaded associations that are not easily
detachable/re-attachable from/to their hibernate session? I was never
sure on how to do this, maybe dto is a healthier alternative despite
introducing a lot of duplication.

Anyway, I've done little tests with spring OpenSessionInViewFilter and
things DO work as I desire. I mean changes are committed only when a
@Transactional method is invoked, not during events that simply update
the model without submitting. I'm still not sure about how this
behaviour is implemented. Perhaps a read-only transaction is started
with the session, then the @Transactional method updates it to
read-write (if this can be done, if not I guess it starts a new one
instead) and commit it upon returning (or rollback it when an
exception is thrown), finally a new read-only transaction is started
(or maybe the old one is resumed...). Well, as you can see, I'm lost
here. This belongs to springforum but anyway: anyone here is aware of
what is happening behind the scenes with OpenSessionInViewFilter and
@Transactional services (defaults for @Transactional: read-write,
propagation-required...)? I mean, which is the transaction before and
after the service method invocation? Would changes occurred during
these before/after transactions be flushed (from my experiments, the
answer is no)?

Best regards,
Carlos

On 4/6/07, Matej Knopp <[EMAIL PROTECTED]> wrote:
> It's not a good idea to use LoadableDetachableModel for entities that
> you edit. Because they are detached after every request.
>
> LoadableDetachableModel is best for View scenarios, when you need
> fresh data on every request. In case you are editing entities, like
> you do, load the entity only once, e.g. when creating the page and set
> it as page property. Without using LoadableDetachableModel.
>
> -Matej
>
> On 4/6/07, Carlos Pita <[EMAIL PROTECTED]> wrote:
> > Same can be said for ajax update behaviour. See for example:
> >
> > TextField password = new TextField("password");
> > AjaxFormComponentUpdatingBehavior ajaxBehaviour =
> >     new AjaxFormComponentUpdatingBehavior("onblur") {
> >         protected void onUpdate(AjaxRequestTarget target) {
> >             System.out.println("ajaxUpdated");
> >          }
> >     };
> > password.add(ajaxBehaviour);
> >
> > The output:
> > -----------------
> >
> > getPassword
> > setPassword <--------------- here
> > ajaxUpdated
> >
> > Should I avoid directly using persistent objects for models? What do
> > you suggest? I could serialize an (hibernate)detached object as a form
> > field and then re-attach it on form submission. Or I could load and
> > (hibernate)detach the object on every request (same as I'm doing now,
> > but detaching from session immediately after loading). Or I could use
> > a plain dto.
> >
> > Cheers,
> > Carlos
> >
> > On 4/5/07, Carlos Pita <[EMAIL PROTECTED]> wrote:
> > > Hi all,
> > >
> > > I'm a bit concerned about onSelectionChanged event effectively binding
> > > my model. Suppose my model is a LoadableDetachableModel that is loaded
> > > from the repository every time. Normally (upon form submission)
> > > nothing will be bound after successfully passing validation; then
> > > additional logic will run inside a transactional service and a
> > > rollback thrown if something goes wrong (take into account that I'm
> > > using session-in-view). But if a property of my model object is bound
> > > outside this controlled scenario, the change will be persisted upon
> > > session correct finalization, even if the object is invalid. I
> > > observed that during onSelectionChanged execution the changed property
> > > is effectively bound, so how should I deal with this?
> > > Here is an example with a simple User that has a sex property allowing
> > > the usual two values, note how setSex is called during execution of
> > > onSelectionChanged:
> > >
> > >
> > > The ouput for onSelectionChanged
> > > --------------------------------------------------
> > >
> > > loadSexModel
> > > getSex
> > > setSex  <------- here
> > > getSex
> > > selectionChanged
> > > getSex
> > >
> > > The user domain entity.
> > > ----------------------------------
> > >
> > > public class User implements Serializable {
> > >     [...]
> > >     private String sex;
> > >
> > >     [...]
> > >     public String getSex() {
> > >         System.out.println("getSex");
> > >         return sex;
> > >     }
> > >
> > >     public void setSex(String sex) {
> > >         System.out.println("setSex");
> > >         this.sex = sex;
> > >     }
> > > }
> > >
> > > The sex choice.
> > > ----------------------
> > >
> > > DropDownChoice sex = new DropDownChoice("sex", getSexModel()) {
> > >   protected void onSelectionChanged(Object newSelection) {
> > >     System.out.println("selectionChanged");
> > >   }
> > >   protected boolean wantOnSelectionChangedNotifications() {
> > >     return true;
> > >   }
> > > };
> > >
> > > The sex model.
> > > ---------------------
> > >
> > > private IModel getSexModel() {
> > >   return new LoadableDetachableModel() {
> > >     protected Object load() {
> > >         System.out.println("loadSexModel");
> > >         return Arrays.asList("Masculine", "Feminine");
> > >       }
> > >     };
> > > }
> > >
> > >
> > > Cheers,
> > > Carlos
> > >
> >
> > -------------------------------------------------------------------------
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to share your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > _______________________________________________
> > Wicket-user mailing list
> > Wicket-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to