Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


entity relationship not populating properly


entity relationship not populating properly  using -'java,spring,hibernate'

In a Spring MVC application using Hibernate, a list that joins two entities in a ManyToMany relationship is not populating properly.  The entities are Encounter and Provider.  The Encounter entity has a property providers, which is a list of Property entities, and which is not populating properly.  Can someone help me figure out how to fix my code so that the entity starts to populate properly?   

The code for the controller method that fails to properly populate the ArrayList is as follows:  

@RequestMapping("/calendar")
public String showCalendar(@RequestParam("day") String day, org.springframework.web.context.request.WebRequest webRequest, Model model) {
    String pid = webRequest.getParameter("pid");
    System.out.println("............ pid is:  " + pid);

    model.addAttribute("pid", pid);
    LocalDate mydate;

    if(day.equals("")) {
      mydate = new LocalDate();
    } else {
      mydate = new LocalDate(day);
    }

    System.out.println("------------------------ in controller, day of month is:  " + mydate.getDayOfMonth());
    AppointmentCalendar calendar = new AppointmentCalendar(mydate); // Or whatever you do to create it
    List<Encounter> encountersforday = (List<Encounter>) clinicService.getEncountersForDay(mydate);

    model.addAttribute("calendar", calendar);
    model.addAttribute("encountersforday", encountersforday);

    System.out.println("number of encountersforday is: " + encountersforday.size());

    List<LocalTime> myblocks = calendar.getBlocks();
    int[][] filledblocks = new int[myblocks.size()][3];
    for (Integer i=0; i < encountersforday.size(); i++) {
        System.out.println("i, encounterid, patientid, first, last, " +
                           "numProviders, dateTime are: " + i + ", " +
                           encountersforday.get(i).getId() + ", " +
                           encountersforday.get(i).getPatient().getId() + ", " +
                           encountersforday.get(i).getPatient().getFirstName() + ", " +
                           encountersforday.get(i).getPatient().getLastName() + ", " +
                           encountersforday.get(i).getProviders().size() + ", " +
                           encountersforday.get(i).getDateTime());
        for (Integer g=0; g < myblocks.size(); g++) {
            filledblocks[g][0] = g;//blockid
            if (myblocks.get(g).getHourOfDay() == encountersforday.get(i).getDateTime().getHourOfDay()) {
                if (myblocks.get(g).getMinuteOfHour() == encountersforday.get(i).getDateTime().getMinuteOfHour()) {
                    int hours = myblocks.get(g).getHourOfDay();
                    int mins = myblocks.get(g).getMinuteOfHour();
                    System.out.println("found match at: "+hours+":"+mins);
                    filledblocks[g][1] = i+1;//encounterid
                    filledblocks[g][2] = 1;//segmentindex
                }
            }
        }
    }

    return "appointments/calendar";
}


The System.out.println() commands in the preceding code output the following:  

number of encountersforday is: 5
i, encounterid, patientid, first, last, numProviders, dateTime are: 0, 1, 5, Peter, McTavish, 0, 2014-01-10T12:00:00.000-08:00
found match at: 12:0
i, encounterid, patientid, first, last, numProviders, dateTime are: 1, 2, 4, Harold, Davis, 0, 2014-01-10T11:30:00.000-08:00
found match at: 11:30
i, encounterid, patientid, first, last, numProviders, dateTime are: 2, 3, 3, Eduardo, Rodriquez, 0, 2014-01-10T10:00:00.000-08:00
found match at: 10:0
i, encounterid, patientid, first, last, numProviders, dateTime are: 3, 4, 2, Morticia, Adams, 0, 2014-01-10T09:30:00.000-08:00
found match at: 9:30
i, encounterid, patientid, first, last, numProviders, dateTime are: 4, 5, 1, Speed, Racer, 1, 2014-01-10T13:30:00.000-08:00
found match at: 13:30  


As you can see from the output above, only one of the Encounter objects has greater than 0 numProviders.  This is true despite the fact that every single one of the Encounters has a Provider specified in the underlying data table.  

NOTE: To simplify this posting, I have uploaded the relevant code to a file sharing site.  You can view the code at the file sharing site by clicking on the links below.

You can read the code for creating and populating the data tables for encounters and providers in the underlying database at this link.  

The code for the Encounter entity is at this link.

The code for the Provider entity is at this link.  

The code for BaseEntity is at this link.  

The code for the Person entity is at this link.  
    

asked Oct 13, 2015 by param.oncemore
0 votes
1 view



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...