Re: LRUMap.reuseMapping exception with 1.2B3

From: Lothar Krenzien (lkrenzie..eb.de)
Date: Thu Jul 27 2006 - 12:13:39 EDT

  • Next message: Nikolai Raitsev: "Re: Objects stored in DB despite optimistic locking"

    Hi Tore,

    the exception occured very often for me in the get/post method of a servlet. After days of searching I found out that I created a new cayenne context for every requests and assigned it to a static variable. And because all other methods used this static variable, which was changed in the meantime by another request, I got the exception. After creating a new context in every post / get request it went away.

    Here's an example of what I did first:

    ------------------ first -----------------------------------
    private static DataContext context;

    private void doPost( ... ) {
     context = ServletUtil.getSessionContext(request.getSession());
     ....
     getLoggerConfig(context );
     ...
    }

    After changing it like this, the problems went away.

    ------------------ second-----------------------------------

    private void doPost( ... ) {
     DataContext context = ServletUtil.getSessionContext(request.getSession());
     ....
     getLoggerConfig(context );
     ...
    }

    But unfortunately after 3 or 4 weeks I got the same error again, but only very rarly. Now I was told that it is forbiden to start a new thread in a servlet. And that's what I did. So hopefully the exception is definitly solved now.

    Also a colleague told me that it can cause problems to create the cayenne context in a servlet like above. Instead of that it should be better to do it like this:

    DataDomain domain = Configuration.getSharedConfiguration().getDomain();
    DataContext dctx = domain.createDataContext();

    Maybe some one other can comment it ?

    Hope that helps.
    Lothar

    > -----Ursprüngliche Nachricht-----
    > Von: cayenne-use..ncubator.apache.org
    > Gesendet: 27.07.06 10:39:32
    > An: cayenne-use..ncubator.apache.org
    > Betreff: LRUMap.reuseMapping exception with 1.2B3

    > Hello.
    >
    > I just got a exception from LRUMap.reuseMapping using cayenne-1.2B3.
    > I remember this discussion earlier this summer, but is it fixed in
    > 1.2 final? CAY-565 are resolved with resolution "Cannot Reproduce"..
    >
    > java.lang.NullPointerException
    > at org.apache.commons.collections.map.LRUMap.reuseMapping
    > (LRUMap.java:235)
    > at org.apache.commons.collections.map.LRUMap.addMapping(LRUMap.java:
    > 211)
    > at org.apache.commons.collections.map.AbstractHashedMap.put
    > (AbstractHashedMap.java:314)
    > at
    > org.objectstyle.cayenne.access.DataDomainQueryAction.interceptOIDQuery
    > (DataDomainQueryAction.java:187)
    > at org.objectstyle.cayenne.access.DataDomainQueryAction.execute
    > (DataDomainQueryAction.java:142)
    > at org.objectstyle.cayenne.access.DataDomain.onQuery(DataDomain.java:
    > 765)
    > at org.objectstyle.cayenne.util.ObjectContextQueryAction.runQuery
    > (ObjectContextQueryAction.java:253)
    > at org.objectstyle.cayenne.access.DataContextQueryAction.execute
    > (DataContextQueryAction.java:90)
    > at org.objectstyle.cayenne.access.DataContext.onQuery
    > (DataContext.java:1422)
    > at org.objectstyle.cayenne.access.DataContext.performQuery
    > (DataContext.java:1411)
    > at org.objectstyle.cayenne.DataObjectUtils.objectForQuery
    > (DataObjectUtils.java:290)
    > at org.objectstyle.cayenne.DataObjectUtils.objectForPK
    > (DataObjectUtils.java:276)
    > at org.objectstyle.cayenne.DataObjectUtils.objectForPK
    > (DataObjectUtils.java:185)
    >
    > - Tore.

    ______________________________________________________________________
    XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
    Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130



    This archive was generated by hypermail 2.0.0 : Thu Jul 27 2006 - 12:14:04 EDT