Return-Path: X-Original-To: apmail-wicket-users-archive@minotaur.apache.org Delivered-To: apmail-wicket-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3F7809CD9 for ; Thu, 14 Mar 2013 08:21:01 +0000 (UTC) Received: (qmail 74864 invoked by uid 500); 14 Mar 2013 08:21:00 -0000 Delivered-To: apmail-wicket-users-archive@wicket.apache.org Received: (qmail 74356 invoked by uid 500); 14 Mar 2013 08:20:59 -0000 Mailing-List: contact users-help@wicket.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@wicket.apache.org Delivered-To: mailing list users@wicket.apache.org Received: (qmail 74326 invoked by uid 99); 14 Mar 2013 08:20:58 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2013 08:20:58 +0000 Received: from localhost (HELO mail-we0-f179.google.com) (127.0.0.1) (smtp-auth username mgrigorov, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2013 08:20:58 +0000 Received: by mail-we0-f179.google.com with SMTP id p43so1884292wea.10 for ; Thu, 14 Mar 2013 01:20:56 -0700 (PDT) X-Received: by 10.180.97.132 with SMTP id ea4mr2081057wib.23.1363249256938; Thu, 14 Mar 2013 01:20:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.152.81 with HTTP; Thu, 14 Mar 2013 01:20:16 -0700 (PDT) In-Reply-To: References: From: Martin Grigorov Date: Thu, 14 Mar 2013 09:20:16 +0100 Message-ID: Subject: Re: Serialization of DAO To: users@wicket.apache.org Content-Type: multipart/alternative; boundary=f46d04426c4eb3457c04d7de33e8 --f46d04426c4eb3457c04d7de33e8 Content-Type: text/plain; charset=UTF-8 Hi, I don't see how you initialize blogDAO. If you don't use wicket-ioc module then you will need to lookup the DAO from the application whenever you need it: public void onSubmit() { BlogDAO blogDao = MyApplication.get().getBlogDAO(); blogDao.save(blog); } This way you wont keep reference to it in the page/component and it wont be serialized. If you use wicket-guice module then you can do: @Inject private BlogDAO blogDao; and use it anywhere. Wicket will use Guice to lookup the bean at component creation but the bean will be wrapped in a serializable proxy. That is a lightweight proxy will be (de)serialized with the page. This is the recommended way. wicket-string works the same way. wicket-cdi leaves the proxy creation to the CDI implementation. On Thu, Mar 14, 2013 at 5:19 AM, Stephen Walsh < stephen@connectwithawalsh.com> wrote: > I'm attempting to implement Guice for my DAO connections as my JBoss server > keeps running out of memory. Not entirely sure why that is, but I'm hoping > this is at least part of it. I read through > http://markmail.org/message/sz64l4eytzc3ctkh and understand why the DAO > needs to be serialized, and I also followed > > https://cwiki.apache.org/confluence/display/WICKET/Wicket%2C+Guice+and+Ibatis+exampleto > try and figure out where and how exactly to inject my DAO. > > My DAO already extends a basic DAO class that has all of the basics for > getting stuff from the database. Neither of these are interfaces (not sure > if this is a problem or not). My DAO works just fine in panels, but as > soon as it's on a page, it throws the not seralizable exception. > Regardless it doesn't really solve the problem of really only needing one > DAO for the whole application instead of creating one whenever it's needed > in every place that it's needed. If I understand dependency injection, > then this is the whole point. > > Here's my class. Hopefully someone can point me in the right direction for > this page and my application class: > > public class EditBlogEntry extends BasePage { > > private Logger logger = LoggerFactory.getLogger(EditBlogEntry.class); > > private Mongo mongo; > private Morphia morphia; > private BlogDAO blogDAO; > > public EditBlogEntry(final Blog blogEntry) { > // Add edit blogPost form to page > Form form = new Form("form"); > form.add(new Button("postIt") { > @Override > public void onSubmit() { > // This merely gets a new mongo instance that has my blog > entry mapped by morphia for saving the whole POJO to mongo > setUpMongo(); > blogDAO.save(blogEntry); > BlogEntryDetails details = new BlogEntryDetails(new > PageParameters().add("id", blogEntry.getObjectId().toString())); > setResponsePage(details); > } > }); > > LoadableDetachableModel ldm = new LoadableDetachableModel() { > @Override > protected Object load() { > // TODO need to set athr only on new blogEntry > blogEntry.setAthr(CampingAwaitsSession.get().getUser()); > return blogEntry; > } > }; > > form.add(new BlogEntryPanel("blogEntry", new > CompoundPropertyModel(ldm))); > add(form); > > } > > Any thoughts? I feel like I understand the concept but the implementation > is throwing me. > > _______________________________________ > Stephen Walsh | http://connectwithawalsh.com > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --f46d04426c4eb3457c04d7de33e8--