-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: ManyToMany+FetchMode.SUBSELECT+2nd level cache= NPE
PostPosted: Thu Dec 14, 2006 2:17 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
I'm using Hibernate 3.2.0, Annotations 3.2.0, and EM 3.2.0.

I have a second level cache on a ManyToMany collection and it will occationally throw an NPE. I have not been able to narrow down exactly when it happens except it appears to be fairly close to after doing a merge that modifies the collection but in the next persistence context I create. Anyone else seen a stack trace similar to this before? If I make Animal.countries not cached then everything works fine. If I remove FetchType.SUBSELECT then everything works fine. Any ideas?

Stacktrace:

Code:
java.lang.NullPointerException
   at org.hibernate.engine.CollectionLoadContext.addCollectionToCache(CollectionLoadContext.java:306)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:203)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
   at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:866)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:853)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:1990)
   at org.hibernate.loader.collection.SubselectCollectionLoader.initialize(SubselectCollectionLoader.java:58)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
   at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
   at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
   at org.hibernate.loader.Loader.doList(Loader.java:2144)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
   at org.hibernate.loader.Loader.list(Loader.java:2023)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)


Animal.java
Code:
public class Animal implements Serializable {
   public static final String QUERY_GET_ALL_ANIMALS_AS_SELECT_ITEMS = "getAllAnimalsAsSelectItems";

   @Id @GeneratedValue
   private Long id;
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATED", nullable = false, updatable = false)
   private Date created = new Date();
   @Column(unique=true, nullable=false)
    private String name;
    @Enumerated(EnumType.STRING)
    private Gender gender;
    @Column(length=4000)
    private String description;
    private String imageUrl;
    private double price;
    private Date dateOfBirth;
    @ManyToOne(fetch=FetchType.LAZY)
    private Classification classification;
    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name="ANIMAL_COUNTRY",
          joinColumns=@JoinColumn(name="ANIMAL_ID"),
          inverseJoinColumns=@JoinColumn(name="COUNTRY_ID"))
    @Fetch(FetchMode.SUBSELECT)
    @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
    private Set<Country> countries;
    @SuppressWarnings("unused")
   @Version
    private Long version;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 4:55 am 
Newbie

Joined: Tue Dec 05, 2006 6:15 pm
Posts: 4
Location: London, England
Don't recognise it - but do you have any more info on what's null (and why) ? Looking at the source, line 306 of CollectionLoadContext is
Code:
version = context.getEntry(context.getCollectionOwner(lce.key,persister) ).getVersion();
.. presumably it's the result of context.getEntry, but a breakpoint on that line (or on NullPointerException) might shed some more light on it.

Also, there's a log line at the start of that method, so turning on debug for org.hibernate.engine.CollectionLoadContext might help.

John

_________________
If you want IT, dowNinja IT.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 6:54 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Thanks for the reply. I forgot to watch the thread. :)

What is actually returning null is the call to context.getCollectionOwner(lce.key, persister). Ice.key and persister appear fine but getCollectionOwner returning null is causing getEntry() to return null which is causing getVersion() to throw the NPE.

Here is the full stack trace with debug turned on for org.hibernate
Code:
15:48:07,046 DEBUG ReadOnlyCache: Caching: org.lds.stack.petstore.model.Country#15
15:48:07,046 DEBUG TwoPhaseLoad: done materializing entity [org.lds.stack.petstore.model.Country#15]
15:48:07,046 DEBUG TwoPhaseLoad: resolving associations for [org.lds.stack.petstore.model.Country#67]
15:48:07,046 DEBUG CollectionLoadContext: creating collection wrapper:[org.lds.stack.petstore.model.Country.animals#67]
15:48:07,046 DEBUG TwoPhaseLoad: adding entity to second-level cache: [org.lds.stack.petstore.model.Country#67]
15:48:07,046 DEBUG ReadOnlyCache: Caching: org.lds.stack.petstore.model.Country#67
15:48:07,046 DEBUG TwoPhaseLoad: done materializing entity [org.lds.stack.petstore.model.Country#67]
15:48:07,046 DEBUG CollectionLoadContext: 55 collections were found in result set for role: org.lds.stack.petstore.model.Animal.countries
15:48:07,046 DEBUG CollectionLoadContext: Caching collection: [org.lds.stack.petstore.model.Animal.countries#46]
15:48:07,078 DEBUG CacheSynchronization: transaction after completion callback, status: 4
15:48:07,078 DEBUG JDBCContext: after transaction completion
15:48:07,078 DEBUG SessionImpl: after transaction completion
15:48:07,078 DEBUG JDBCContext: TransactionFactory reported no active transaction; Synchronization not registered
15:48:07,078 DEBUG JDBCContext: TransactionFactory reported no active transaction; Synchronization not registered
15:48:07,078 DEBUG JDBCContext: TransactionFactory reported no active transaction; Synchronization not registered
Jan 17, 2007 3:48:07 PM com.sun.facelets.FaceletViewHandler handleRenderException
SEVERE: Error Rendering View[/pet-search.xhtml]
javax.faces.FacesException: javax.el.ELException: /pet-search.xhtml @59,97 rendered="#{empty petSearchBean.currentResults}": java.lang.NullPointerException
   at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:387)
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:878)
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:890)
   at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:571)
   at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:101)
   at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:222)
   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:248)
   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:75)
   at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:213)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
   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:274)
   at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
   at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)
Caused by: javax.el.ELException: /pet-search.xhtml @59,97 rendered="#{empty petSearchBean.currentResults}": java.lang.NullPointerException
   at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
   at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:384)
   ... 55 more
Caused by: java.lang.NullPointerException
   at org.hibernate.engine.CollectionLoadContext.addCollectionToCache(CollectionLoadContext.java:306)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:203)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
   at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
   at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:866)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:853)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:2057)
   at org.hibernate.loader.collection.SubselectCollectionLoader.initialize(SubselectCollectionLoader.java:58)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
   at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
   at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
   at org.hibernate.loader.Loader.doList(Loader.java:2211)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
   at org.hibernate.loader.Loader.list(Loader.java:2090)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
   at org.lds.stack.serviceproxy.jpa.hibernate.AbstractQueryFindExecutor.executeQuery(AbstractQueryFindExecutor.java:44)
   at org.lds.stack.serviceproxy.jpa.FindInterceptor$1.doInJpa(FindInterceptor.java:42)
   at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
   at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:146)
   at org.lds.stack.serviceproxy.jpa.FindInterceptor.invoke(FindInterceptor.java:38)
   at org.lds.stack.serviceproxy.ServiceProxyCglibInterceptor.intercept(ServiceProxyCglibInterceptor.java:48)
   at org.lds.stack.petstore.service.AbstractAnimalService$$EnhancerByCGLIB$$f5d1e271.searchForAnimals(<generated>)
   at org.lds.stack.petstore.service.AnimalService$$FastClassByCGLIB$$5fa987b7.invoke(<generated>)
   at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:163)
   at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:674)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:615)
   at org.lds.stack.petstore.service.AbstractAnimalService$$EnhancerByCGLIB$$8b94a5b3.searchForAnimals(<generated>)
   at org.lds.stack.petstore.view.bean.PetSearchBean.getCurrentResults(PetSearchBean.java:54)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at javax.el.BeanELResolver.getValue(BeanELResolver.java:218)
   at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
   at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
   at com.sun.el.parser.AstValue.getValue(AstValue.java:118)
   at com.sun.el.parser.AstEmpty.getValue(AstEmpty.java:49)
   at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
   at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
   ... 56 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:34 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Upgraded to Hibernate 3.2.2 and am still experiencing this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 1:53 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Created JIRA issue: http://opensource.atlassian.com/project ... e/HHH-2391


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.