Retrieve primary key column definition of a generic entity in JPA
问题 Let say I have a generic method using JPA to list out entities public <T> List<T> list(Class<T> entity) throws Exception { List<T> result = new ArrayList<T>(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<T> query = builder.createQuery( entity ); Root<T> root = query.from( entity ); query.select( root ); //possible? query.orderBy(builder.asc(...)); result = em.createQuery( query ).getResultList(); return result; } Is there anyway for us to add orderby to the query and make