1 Reply Latest reply on Aug 1, 2012 10:17 AM by Scott Marlow

    Hibernate-Infinispan NullPointerException in CacheKey.equals method

    Charles Akalugwu Newbie

      I am trying to use Infinispan 5.1.5 Final in my app. I use the following environment:

       

      JBoss AS 7.1.1 Final

      Hibernate Core 4.1.5.SP1

      Hibernate Search 4.1.1 Final

      Infinispan 5.1.5 Final

      JBoss Seam 2.3.0 Beta2

       

      At application startup, I try to see if the admin user accounts exist and if they don't I create them. As follows:

       

      private void initDefaultUsersAndRoles(){

       

              log.info("Initializing Default Roles And Passwords");

       

              Role adminRole = roleDAO.getByName("administrator");

       

              if (adminRole == null) {

                 //create new admin role

              }

       

       

              User admin = userDAO.findByUsername("admin ");

       

              if (admin  == null) {

                  //create new admin user

              }

      }

       

       

      I get an exception in the userDAO.findByUsername method which is shown below:

       

      public User findByUsername(String username) {

                          User user;

                          try{

                                    Query q = getEm().createQuery("SELECT e FROM "

                                                        + entityClass.getName() + " e WHERE username = :username");

                                    q.setParameter("username", username );

                                    q.setHint("org.hibernate.cacheable", "true" );

       

                                    user = (User) q.getSingleResult();

                          }

                          catch( NoResultException e ){

                                    return null;

                          }

                          return user;

      }

       

      Upon execution of

       

      user = (User) q.getSingleResult()

       

      I get the following error:

       

      18:44:52,097 ERROR [org.infinispan.interceptors.InvocationContextInterceptor] (MSC service thread 1-8) ISPN000136: Execution error: java.lang.NullPointerException

                at org.hibernate.cache.spi.CacheKey.equals(CacheKey.java:81) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.infinispan.context.SingleKeyNonTxInvocationContext.lookupEntry(SingleKeyNonTxInvocationContext.java:93)

                at org.infinispan.container.EntryFactoryImpl.getFromContext(EntryFactoryImpl.java:204)

                at org.infinispan.container.EntryFactoryImpl.wrapEntryForReading(EntryFactoryImpl.java:80)

                at org.infinispan.interceptors.EntryWrappingInterceptor.visitGetKeyValueCommand(EntryWrappingInterceptor.java:112)

                at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:60)

                at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)

                at org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor.visitGetKeyValueCommand(NonTransactionalLockingInterceptor.java:57)

                at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:60)

                at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)

                at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:130)

                at org.infinispan.commands.AbstractVisitor.visitGetKeyValueCommand(AbstractVisitor.java:104)

                at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:60)

                at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)

                at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:132)

                at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:91)

                at org.infinispan.commands.AbstractVisitor.visitGetKeyValueCommand(AbstractVisitor.java:104)

                at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:60)

                at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)

                at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:130)

                at org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager$ClassLoaderAwareCommandInterceptor.handleDefault(DefaultEmbeddedCacheManager.java:410)

                at org.infinispan.commands.AbstractVisitor.visitGetKeyValueCommand(AbstractVisitor.java:104)

                at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:60)

                at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:345)

                at org.infinispan.CacheImpl.containsKey(CacheImpl.java:259)

                at org.infinispan.DecoratedCache.containsKey(DecoratedCache.java:309)

                at org.infinispan.AbstractDelegatingCache.containsKey(AbstractDelegatingCache.java:293)

                at org.hibernate.cache.infinispan.util.CacheAdapterImpl.containsKey(CacheAdapterImpl.java:214) [hibernate-infinispan-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.cache.infinispan.access.TransactionalAccessDelegate.putFromLoad(TransactionalAccessDelegate.java:87) [hibernate-infinispan-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.cache.infinispan.entity.TransactionalAccess.putFromLoad(TransactionalAccess.java:52) [hibernate-infinispan-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:224) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:998) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.doQuery(Loader.java:877) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:292) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.doList(Loader.java:2381) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2226) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.Loader.list(Loader.java:2189) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]

                at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:285) [hibernate-entitymanager-4.1.5.SP1.jar:4.1.5.SP1]

                at com.cano.pxt.dao.UserDAO.findByUsername(UserDAO.java:35) [pxt-ejb.jar:]

       

       

       

      My persistence.xml contains the following lines for hibernate query and 2nd-level caching:

       

      <property name="hibernate.cache.region.factory_class" value="org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory" />

      <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/hibernate" />

       

       

      My User entity class has the equals and hashCode methods implemented.

       

      Does anyone have an idea what might be wrong? Thanks in advance.