NullPointerException loading an EJB 2 CMP Relation in JBoss EAP?

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP) 5.x

Issue

  • Migrating an application from OAS to EAP 5.1.1 and have hit a problem with CMP Entity Bean relationships getting this exception:

    ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.util.Collection com.jboss.examples.ejb2.entity.ExampleLocal.getExampleAttribute(), causedBy:
    java.lang.NullPointerException
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.execute(JDBCLoadRelationCommand.java:170)
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadRelation(JDBCStoreManager.java:705)
    at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load(JDBCCMRFieldBridge.java:1414)
    at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getInstanceValue(JDBCCMRFieldBridge.java:729)
    at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue(JDBCCMRFieldBridge.java:681)
    at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler$FieldGetInvoker.invoke(EntityBridgeInvocationHandler.java:147)
    at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java
    ...
    

Resolution

Implement the hashCode on your pk classes.  The hashCode and equals should be consistent.

  public int hashCode()
  {
    // Add custom hashCode() impl here
    return super.hashCode();
  }

Root Cause

Missing hashCode implementation

Diagnostic Steps

Review the server.log, ejb-jar.xml, and jbosscmp-jdbc.xml.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.