ManagedEntityManagerFactory factory=
((PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(kernelName)).getManagedFactory();
if (factory != null)
{
em = factory.createEntityManager();
if (em != null)
{
for( StatefulBeanContext bc : beanContexts)
{
bc.addExtendedPersistenceContext(kernelName, em);