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 <[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 > -- Pieter Claassen musmato.com --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
