Is there any other way to reduce the below code snippet. Before we are using Hibernate4 current we changing to Hibernate5(Version 5.3.6.Final) so there are so many changes in Hibernate5. We are new to this version so anyone shares us any code snippet for calling any stored procedure in Hibernate5. We already did it working but we need some standard optimized code.
Here we are using the following method.
@Override
public List<LocationCount> getLocationCounts(String userName) {
StoredProcedureQuery q = getCurrentSession().createStoredProcedureQuery("locationcount");
q.registerStoredProcedureParameter("userName", String.class, ParameterMode.IN);
q.setParameter("userName", userName);
q.execute();
List<LocationCount> data = new ArrayList<>();
List<Object[]> results = q.getResultList();
results.stream().forEach((record) -> {
LocationCount d = new LocationCount();
d.setOrgCode((String) record[0]);
d.setOrgName((String) record[1]);
d.setLocationCode((String) record[2]);
d.setLocationName((String) record[3]);
data.add(d);
});
return data;
}
Thanks
Sitansu