You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2008/01/12 01:42:10 UTC

Strange Exception

Hi All!

'm havign a strange problem under Cayenne 3.0M2 which is very intermitent.
Using a web application backed by Cayenne, the user modifies property
records in the database via a web interface. Everything runs fine until one
of the modifications cause the following exception:

[2008-01-12 11:32:13,174] ERROR org.mortbay.log (JCLLoggerAdapter.java:543)
- Nested in javax.servlet.ServletException: [v.3.0M2 Oct 28 2007 16:09:02]
Commit Exception:
org.apache.cayenne.CayenneRuntimeException: [v.3.0M2 Oct 28 2007 16:09:02]
Commit Exception
        at org.apache.cayenne.access.DataContext.flushToParent(
DataContext.java:1202)
        at org.apache.cayenne.access.DataContext.commitChanges(
DataContext.java:1083)
        at au.com.jarrel.commons.db.cayenne.dao.impl.BaseDaoImpl.commit(
BaseDaoImpl.java:91)
        at
au.com.hybridkinetic.jarrel.web.action.admin.listing.AddListing.runAction(
AddListing.java:72)
        at au.com.hybridkinetic.jarrel.web.action.BaseAction.execute(
BaseAction.java:80)
        at org.apache.struts.action.RequestProcessor.processActionPerform(
RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(
RequestProcessor.java:236)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java
:1196)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java
:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java
:487)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1087)
        at net.sf.ehcache.constructs.web.filter.GzipFilter.doFilter(
GzipFilter.java:75)
        at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java
:92)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at
org.riotfamily.common.web.filter.CharacterEncodingFilter.doFilterInternal(
CharacterEncodingFilter.java:95)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(
OncePerRequestFilter.java:75)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at
au.com.jarrel.commons.db.cayenne.i18n.web.filter.LocaleEnforecementFilter.doFilter
(LocaleEnforecementFilter.java:59)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at
au.com.jarrel.commons.db.cayenne.i18n.web.filter.JstlLocaleFilter.doFilter(
JstlLocaleFilter.java:125)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at
au.com.jarrel.commons.db.cayenne.i18n.web.filter.LocaleSettingFilter.doFilter
(LocaleSettingFilter.java:110)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at au.com.hybridkinetic.jarrel.web.RequestUrlFilter.doFilter(
RequestUrlFilter.java:52)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:265)
        at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(
FilterSecurityInterceptor.java:107)
        at
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(
FilterSecurityInterceptor.java:72)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(
ExceptionTranslationFilter.java:110)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at
org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(
AnonymousProcessingFilter.java:125)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at
org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(
SecurityContextHolderAwareRequestFilter.java:81)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(
AbstractProcessingFilter.java:229)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at org.acegisecurity.ui.logout.LogoutFilter.doFilter(
LogoutFilter.java:106)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at
org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(
HttpSessionContextIntegrationFilter.java:286)
        at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(
FilterChainProxy.java:275)
        at org.acegisecurity.util.FilterChainProxy.doFilter(
FilterChainProxy.java:149)
        at org.acegisecurity.util.FilterToBeanProxy.doFilter(
FilterToBeanProxy.java:98)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at org.apache.cayenne.conf.WebApplicationContextFilter.doFilter(
WebApplicationContextFilter.java:91)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
ServletHandler.java:1078)
        at org.mortbay.jetty.servlet.ServletHandler.handle(
ServletHandler.java:361)
        at org.mortbay.jetty.security.SecurityHandler.handle(
SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(
SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(
ContextHandler.java:712)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java
:406)
        at org.mortbay.jetty.handler.ContextHandlerCollection.handle(
ContextHandlerCollection.java:211)
        at org.mortbay.jetty.handler.HandlerCollection.handle(
HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(
HandlerWrapper.java:139)
        at org.mortbay.jetty.Server.handle(Server.java:309)
        at org.mortbay.jetty.HttpConnection.handleRequest(
HttpConnection.java:506)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(
HttpConnection.java:844)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(
SelectChannelEndPoint.java:396)
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(
BoundedThreadPool.java:442)
Caused by: java.lang.NullPointerException
        at org.apache.cayenne.access.DataContext$1.visitToOne(
DataContext.java:599)
        at org.apache.cayenne.reflect.generic.DataObjectToOneProperty.visit(
DataObjectToOneProperty.java:85)
        at
org.apache.cayenne.reflect.PersistentDescriptor.visitDeclaredProperties(
PersistentDescriptor.java:323)
        at org.apache.cayenne.reflect.PersistentDescriptor.visitProperties(
PersistentDescriptor.java:358)
        at
org.apache.cayenne.reflect.LazyClassDescriptorDecorator.visitProperties(
LazyClassDescriptorDecorator.java:138)
        at org.apache.cayenne.access.DataContext.currentSnapshot(
DataContext.java:543)
        at org.apache.cayenne.access.DataDomainSyncBucket.postprocess(
DataDomainSyncBucket.java:230)
        at org.apache.cayenne.access.DataDomainFlushAction.postprocess(
DataDomainFlushAction.java:240)
        at org.apache.cayenne.access.DataDomainFlushAction.flush(
DataDomainFlushAction.java:148)
        at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java
:827)
        at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java
:794)
        at org.apache.cayenne.access.DataDomain.runInTransaction(
DataDomain.java:853)
        at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:791)
        at org.apache.cayenne.access.DataContext.flushToParent(
DataContext.java:1170)
        ... 63 more

I can not seem to establish a pattern to why this happens, it will usually
happen within the first 10 - 15 commits  the application does, after the
server starts.

I've started checking the objects in the context. When the commit works fine
there are no modified and/or uncommitted objects in the graph. But as soon
as this happens there graph contains the object/record which I was working
with in both modified and committed state. This object is then stuck in the
context so any further work with the application would cause the same
failure.

The main question is if anyone has any clue to what could cause this
exception?

The second is how do people handle objects handing around in the graph if an
exception is thrown during comit? Perhaps one solution is to catch the
Exception in the web filter, rollback any changes on the context and remove
all the dirty objects in the graph? But this does not sound very clean to
me?

Thank you in advance!

Cheers,
Gary

Re: Strange Exception

Posted by Gary Jarrel <ga...@gmail.com>.
<snip>
>
>
> >
> > Hmm... the line in question is:
> >
> > Map idParts = target.getObjectId().getIdSnapshot();
> >
> > I can't imagine why the objectId for the target (toOne) record is
> > null. (target can't be null in that bit of code.) Perhaps you can
> > examine the contents of your context at that point a bit further to
> > glean more information.
>
>
> I have looked at that line as well and it didn't make sense to me on how
> it could throw a NPE especially given that it tends to work most of the
> time! I'll investigate in the debugger in a minute and will report.
>
>

Well the problem appears to have been due to my silliness! I had a
"property" object and one of the one-to-many relationships to "property
features". And in one part of the code I was unregistering the "property"
object from the data context using the unregister objects method however I
was not cleaning up any of the relationships. Perhaps on the next request
these "property feature" objects were sitting in the context. So I take it
the WebApplicationContextFilter does not throw away the data context after
the chain completes?

Thank you for the wonderful help as always!

- garyj

Re: Strange Exception

Posted by Gary Jarrel <ga...@gmail.com>.
Thank you for the quick reply!

On Jan 12, 2008 12:22 PM, Aristedes Maniatis <ar...@ish.com.au> wrote:

>
> On 12/01/2008, at 11:42 AM, Gary Jarrel wrote:
>
> > Caused by: java.lang.NullPointerException
> >        at org.apache.cayenne.access.DataContext$1.visitToOne(
> > DataContext.java:599)
>
> Hmm... the line in question is:
>
> Map idParts = target.getObjectId().getIdSnapshot();
>
> I can't imagine why the objectId for the target (toOne) record is
> null. (target can't be null in that bit of code.) Perhaps you can
> examine the contents of your context at that point a bit further to
> glean more information.


I have looked at that line as well and it didn't make sense to me on how it
could throw a NPE especially given that it tends to work most of the time!
I'll investigate in the debugger in a minute and will report.


>
>
> As for your question about handling the exception, it sounds like the
> easiest approach is to throw out the context and create a new one. Are
> you using one context per logged in web session?


I tend to use the WebApplicationContextFilter to handle thread binding of
the data context. Is there another strattegy for disposing of the data
context for every request? As I do not thinl that the
WebApplicationContextFilter actually disposes of the context!


>
>
> Interesting site by the way: I've done a bit of work for real estate
> agents and it was unusual to find technology literate agents.
>

Thank you! :) I will second that about real estate agents. I do both real
estate and IT (yes I know it sounds strange) and the contrast in how people
respond to you when you tell them that you are a real estate agent vs an IT
consultant is astonishing! My advice is to stick to IT :)


>
> Cheers
> Ari Maniatis
>

Thank you for the reply!
Gary

Re: Strange Exception

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 12/01/2008, at 11:42 AM, Gary Jarrel wrote:

> Caused by: java.lang.NullPointerException
>        at org.apache.cayenne.access.DataContext$1.visitToOne(
> DataContext.java:599)

Hmm... the line in question is:

Map idParts = target.getObjectId().getIdSnapshot();

I can't imagine why the objectId for the target (toOne) record is  
null. (target can't be null in that bit of code.) Perhaps you can  
examine the contents of your context at that point a bit further to  
glean more information.

As for your question about handling the exception, it sounds like the  
easiest approach is to throw out the context and create a new one. Are  
you using one context per logged in web session?

Interesting site by the way: I've done a bit of work for real estate  
agents and it was unusual to find technology literate agents.

Cheers
Ari Maniatis


-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A