try {
// do we have a present JPAContext for this db-config in current thread?
JPAConfig jpaConfig = JPA.getJPAConfig(dbConfigName, true);
if (jpaConfig!=null) {
JPAContext jpaContext = jpaConfig.getJPAContext();
return ((SessionImpl)((org.hibernate.ejb.EntityManagerImpl) jpaContext.em()).getSession()).connection();
}
// do we have a current raw connection bound to thread?
if (localConnection.get() != null) {
return localConnection.get();