jpa返回List>相当于jdbctemplate的queryForlist

时间:2022-10-13 15:57:13
public class Test(){
@PersistenceContext(unitName = "manageFactory")
protected EntityManager em;
public List<Map<String, Object>>getListMap(String sql){
        Query nativeQuery=em.createNativeQuery(sql);
        nativeQuery.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        List resultList=nativeQuery.getResultList();
        return resultList;
        }

        }