I needed to extract data from my repository which could not be extracted using the common conventions afforded by spring boot. I found a solution by sticking the queries inside the repository class like so:
@Repository
public interface BarbToiletryOrderRepository extends CrudRepository<BarbToiletryOrder, Integer> {
@Query(value = "SELECT item_total_cost_us FROM barb_toiletry_order", nativeQuery = true)
public List<Object[]> findTotalOneRowCost();
@Query (value = "SELECT id FROM barb_toiletry_order", nativeQuery = true )
public List<Object[]>findId();
}
But then I initiated the queries from within a method of the service class as shown below. So that I could get real data instead of memory locations, I had to come up with strange parsing code for both queries. How could I have avoided all this tweaking? I tried generating "equals() and hashcode()" as well as "toString()" code to no avail.
List<Object[]> costGrandTallyList = barbToiletryOrderRepository.findTotalOneRowCost();
List<Object[]> idList = barbToiletryOrderRepository.findId();
for (Object[] insideArray : costGrandTallyList){
String useArray = Arrays.toString(insideArray);
StringBuffer ta = new StringBuffer(useArray);
ta.delete(useArray.length() - 1, useArray.length());
ta.delete(0, 1);
Double tempDec = Double.valueOf(String.valueOf(ta));
String useArray2 = Arrays.toString(idList.get(i));
StringBuffer ta2 = new StringBuffer(useArray2);
ta2.delete(useArray2.length() - 1, useArray2.length());
ta2.delete(0,1);
Integer intVal = Integer.valueOf(String.valueOf(ta2));
costGrandTally = costGrandTally + tempDec;
}