jpa返回List<Map<String, Object>>相当于jdbctemplate的queryForlist ...

卫博学
2023-12-01
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;
        }

        }

 

 类似资料: