protected EntityManager getEntityManager() { if (!getContext().isParameterSet(INVOCATION_CTX_ENTITY_MANAGER)) { throw new IllegalStateException("Error while trying to determine EntityManager - context parameter not set."); } return (EntityManager) getContext().getParameter(INVOCATION_CTX_ENTITY_MANAGER); }