log.debug("Binding session to current transaction");
try {
Object r;
if (tx instanceof XaTransaction) {
if (isUnmanagedPoolAndOpenJpa) {
r = new JpaXaResourceForTomcatAndOpenJpa(entityManager);
} else {
r = new JpaXaResource(entityManager);
}
} else {
r = entityManager;