This is indeed a solution, but I still think I'm doing something wrong.
Even simple properties of the Employee (like name) are reloaded from the
database for each Ajax request I do....
(so, I mean: when I change first the name of the Employee and I click on the
'add Account' link, my name-change is reverted....)

Isn't there a 'generic' approach for this?

On Tue, Nov 10, 2009 at 9:38 PM, Pedro Santos <[email protected]> wrote:

> You can keep the transient account beans in an list on your LDM, and add
> then to your Employee property on every load...
>
> LDM{
> List transientAccounts;// get serialized with LDM
> load(){
> Employee e = service.search(id);
> e.add(transientAccounts);
> }
> }
>
> On Tue, Nov 10, 2009 at 6:31 PM, Pieter Degraeuwe <
> [email protected]> wrote:
>
> > Thanks for your reply. In some situations your solution might be
> > sufficient,
> > but in my situation I'm affraid not...
> >
> > I cannot commit an empty Account in the db due constraint reasons. And, I
> > actually only want to save the Employee in the database when the user
> > presses the ' Save' button, not when he is adding/ modifying some
> Accounts.
> > (So, in other words, the user can always 'Cancel' his actions...
> >
> >
> >
> > On Tue, Nov 10, 2009 at 9:16 PM, pieter claassen
> > <[email protected]>wrote:
> >
> > > Hi Pieter,
> > >
> > > I don't use Hibernate, but db4o. The principle however  might help you.
> > >
> > > I inject my factory methods into my pages using Spring (but that is a
> > > minor detail) and when I make a change to a domain object, I always
> > > store the object first before reloading the page (or in this case,
> > > rendering the ajax changes). When the page reloads, it loads the
> > > modified object from the database. This is important to also ensure
> > > your domain objects are persisted otherwise, they might still hang
> > > around in wicket, but might not be stored in the db.
> > >
> > > So you need to do something like
> > >
> > > public void onClick(AjaxRequestTarget target){
> > >   employee. addAccount(new Account());
> > >   employeeFactory.store(employee);
> > > ...
> > > }
> > >
> > >
> > > Rgds,
> > > Pieter
> > >
> > > On Tue, Nov 10, 2009 at 9:00 PM, Pieter Degraeuwe
> > > <[email protected]> wrote:
> > > > Hi,
> > > >
> > > > I can't imagine that I'm the only one with the following situation.
> > > >
> > > > I have a page which edits an 'Employee'. Since I use hibernate and
> > spring
> > > I
> > > > use the LDM togeather with the OpenSessionInView.
> > > > This works great (==No more LazyLoadExceptions at all...)
> > > >
> > > > But.... The Employee has a propertie accounts, which is a collection
> of
> > > > Account objects. I'm showing these objects using a Listview.
> > > > Now I want to add an Ajax link ('Add new account), which adds a fresh
> > new
> > > > Account object. I add the containing form to the AjaxRequestTarget so
> > the
> > > > ListView refreshes.
> > > >
> > > > Unfortunately, this approach never works, since my Employee is always
> > > > reloaded from the database each reques.
> > > >
> > > > (I even think the same problem shows up when you do the same without
> > > ajax..)
> > > >
> > > > What is the best approach to deal with this?
> > > >
> > > > --
> > > > Pieter Degraeuwe
> > > > Systemworks bvba
> > > > Belgiëlaan 61
> > > > 9070 Destelbergen
> > > > GSM: +32 (0)485/68.60.85
> > > > Email: [email protected]
> > > > visit us at http://www.systemworks.be
> > > >
> > >
> > >
> > >
> > > --
> > > Pieter Claassen
> > > musmato.com
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
> >
> >
> > --
> > Pieter Degraeuwe
> > Systemworks bvba
> > Belgiëlaan 61
> > 9070 Destelbergen
> > GSM: +32 (0)485/68.60.85
> > Email: [email protected]
> > visit us at http://www.systemworks.be
> >
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>



-- 
Pieter Degraeuwe
Systemworks bvba
Belgiëlaan 61
9070 Destelbergen
GSM: +32 (0)485/68.60.85
Email: [email protected]
visit us at http://www.systemworks.be

Reply via email to