public static JPQLTemplates getTemplates(EntityManager em) {
        for (Map.Entry<Class<?>, JPQLTemplates> entry : mappings.entrySet()) {
            Class<?> entityManagerClass = entry.getKey();
            try {
                if (entityManagerClass.isInstance(em.unwrap(entityManagerClass))) {
                    return entry.getValue();
                }
            } catch (Exception e) { // The PersistenceException is wrapped in an InvocationException for EclipseLink
                // detect by delegate
                if (entityManagerClass.isAssignableFrom(em.getDelegate().getClass())) {
                    return entry.getValue();
                }
            }
        }
        // detect by properties
        for (String key : em.getEntityManagerFactory().getProperties().keySet()) {
            key = key.toLowerCase();
            for (Map.Entry<String, JPQLTemplates> entry : templatesByName.entrySet()) {
                if (key.contains(entry.getKey())) {
                    return entry.getValue();
                }
            }
        }
        return JPQLTemplates.DEFAULT;
    }
{@code JPAProvider} provides detection of the JPA provider based on the EntityManager instance

@author tiwe
querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAProvider.java