Re: editing objects, backed by LoadableDetachableModels
Hi Pieter, Ok, what I do in situations like this is to create a new transient, serializable object (not stored in the DB) and pass it between wicket pages as needed. With db4o, any java object can be stored at some point by calling factory.store(object). Not sure about hibernate. Imagine you need to configure an object using multiple screens in a wizzard. Then just create the object, pass it from page to page in the constructors and in the last page, store it in the db. Rgds, Pieter On Tue, Nov 10, 2009 at 9:31 PM, Pieter Degraeuwe 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 > 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 >> 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: pieter.degrae...@systemworks.be >> > visit us at http://www.systemworks.be >> > >> >> >> >> -- >> Pieter Claassen >> musmato.com >> >> - >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> > > > > -- > Pieter Degraeuwe > Systemworks bvba > Belgiëlaan 61 > 9070 Destelbergen > GSM: +32 (0)485/68.60.85 > Email: pieter.degrae...@systemworks.be > visit us at http://www.systemworks.be > -- Pieter Claassen musmato.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: editing objects, backed by LoadableDetachableModels
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 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 < > pieter.degrae...@systemworks.be> 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 > > 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 > > > 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: pieter.degrae...@systemworks.be > > > > visit us at http://www.systemworks.be > > > > > > > > > > > > > > > > -- > > > Pieter Claassen > > > musmato.com > > > > > > - > > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > > > > > > -- > > Pieter Degraeuwe > > Systemworks bvba > > Belgiëlaan 61 > > 9070 Destelbergen > > GSM: +32 (0)485/68.60.85 > > Email: pieter.degrae...@systemworks.be > > 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: pieter.degrae...@systemworks.be visit us at http://www.systemworks.be
Re: editing objects, backed by LoadableDetachableModels
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 < pieter.degrae...@systemworks.be> 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 > 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 > > 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: pieter.degrae...@systemworks.be > > > visit us at http://www.systemworks.be > > > > > > > > > > > -- > > Pieter Claassen > > musmato.com > > > > - > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > -- > Pieter Degraeuwe > Systemworks bvba > Belgiëlaan 61 > 9070 Destelbergen > GSM: +32 (0)485/68.60.85 > Email: pieter.degrae...@systemworks.be > visit us at http://www.systemworks.be > -- Pedro Henrique Oliveira dos Santos
Re: editing objects, backed by LoadableDetachableModels
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 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 > 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: pieter.degrae...@systemworks.be > > visit us at http://www.systemworks.be > > > > > > -- > Pieter Claassen > musmato.com > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Pieter Degraeuwe Systemworks bvba Belgiëlaan 61 9070 Destelbergen GSM: +32 (0)485/68.60.85 Email: pieter.degrae...@systemworks.be visit us at http://www.systemworks.be
Re: editing objects, backed by LoadableDetachableModels
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 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: pieter.degrae...@systemworks.be > visit us at http://www.systemworks.be > -- Pieter Claassen musmato.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
editing objects, backed by LoadableDetachableModels
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: pieter.degrae...@systemworks.be visit us at http://www.systemworks.be