We are implementing a HealthCheck function for our Kundera app, built on a Cassandra datastore. The implementation using a simple native query against the local system keyspace to ensure datastore connectivity.
We have 4 applications built, each accessing a different set of column families defined as JPA entities in different keyspaces of the Cassandra cluster. 3 of 4 applications have a perfectly functional healthcheck (written exactly the same in each app), but the 4th is throwing a NullPointerException (NPE).
Our code is:
@Override
public boolean isDataStoreAvailable() {
int size = 0;
try {
final Query query = emf.createEntityManager().createNativeQuery("select cluster_name from system.local");
@SuppressWarnings("unchecked")
final List<String> result = query.getResultList();
LOGGER.debug("cluster_name="+result);
size = result.size();
} catch (Exception e) {
LOGGER.error("Unable to retrieve the cluster name from the system.local columnfamily", e);
return false;
}
return size > 0;
}
where emf is an injected EntityManagerFactory.
The application that has the problem with this native query is the only one of our apps that use JPA lifecycle methods. In one of our entities, we define a postLoad method, using the javax.persistence.PostLoad annotation.
When our app fails, we see the following messages in our log file:
Oct-28 16:27:49-TRACE [net.dataforte.cassandra.pool.ConnectionPool] - [Cassandra Connection Pool[1-1062412937]] ConnectionPool: automaticHostDiscovery=false
Oct-28 16:27:49-INFO [com.impetus.kundera.persistence.EntityManagerFactoryImpl] - EntityManagerFactory created for persistence unit : nick-unit
Oct-28 16:29:02-DEBUG [com.nick.web.resource.StatusHandler] - [method => getStatus, annotations => @javax.ws.rs.GET(); @javax.ws.rs.Path(value=status/); @javax.ws.rs.Produces(value=[application/xml])]
Oct-28 16:29:02-DEBUG [com.impetus.kundera.persistence.EntityManagerImpl] - Creating EntityManager for persistence unit : nick-unit
Oct-28 16:29:02-INFO [com.impetus.kundera.persistence.EntityManagerImpl] - Returning client instance for persistence unit nick-unit.
Oct-28 16:29:02-DEBUG [com.impetus.kundera.loader.GenericClientFactory] - Returning fresh client instance for persistence unit : nick-unit
Oct-28 16:29:02-DEBUG [com.impetus.kundera.persistence.EntityManagerImpl] - Created EntityManager for persistence unit : nick-unit
Oct-28 16:29:02-INFO [com.impetus.kundera.query.QueryImpl] - On getResultList() executing query: select cluster_name from system.local
Oct-28 16:29:02-DEBUG [javax.persistence.EntityManager] - Callback >> PostLoad on com.nick.model.ProductPricing
Oct-28 16:29:02-DEBUG [javax.persistence.EntityManager] - Firing >> com.nick.model.ProductPricing.postLoad
Oct-28 16:29:02-ERROR [com.nick.dao.impl.HealthCheckDaoImpl] - Unable to retrieve the cluster name from the system.local columnfamily
java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.impetus.kundera.persistence.event.InternalCallbackMethod.invoke(InternalCallbackMethod.java:67)
at com.impetus.kundera.persistence.event.EntityEventDispatcher.fireEventListeners(EntityEventDispatcher.java:62)
at com.impetus.kundera.query.QueryImpl.handlePostEvent(QueryImpl.java:973)
at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:153)
at com.nick.dao.impl.HealthCheckDaoImpl.isDataStoreAvailable(HealthCheckDaoImpl.java:40)
On my simplistic first glance, I would say that com.impetus.kundera.persistence.event.EntityEventDispatcher.fireEventListeners(EntityEventDispatcher.java:62) should be checking for a null entity being passed in, but equally you could make a case for com.impetus.kundera.query.QueryImpl.handlePostEvent(QueryImpl.java:973) not explicitly passing a null in the call.
We are using Kundera 2.13 and have not yet tried upgrading to 2.14 as there was no encouragement in the release notes or JIRA.
If anyone can throw light on how this can fixed, or would like a JIRA defect creating, please let me know ASAP.
Thanks,
Nick.