Jpa调用存储过程及参数

public List<Object> findAllEntityListBySearch(Long inputInfoId, int flag) throws Exception {
List<Object> infoviewList=new ArrayList<>();
EntityManager em = emf.createEntityManager();
try {
StoredProcedureQuery storedProcedure =em.createStoredProcedureQuery("存储名称");

//下面是参数
storedProcedure.registerStoredProcedureParameter("InputInfoID", Integer.class, ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("Flags", Integer.class, ParameterMode.IN);

//参数赋值
storedProcedure.setParameter("InputInfoID",inputInfoId.intValue());
storedProcedure.setParameter("Flags",flag);

//返回list
infoviewList=storedProcedure.getResultList();
storedProcedure.execute();
} catch (Exception ex) {
logger.error("{} method thrown exception++++++","findAllEntityListBySearch", ex);
} finally {
em.close();
}
return infoviewList;
}

原文地址:https://www.cnblogs.com/yinchuan/p/7298219.html