实体关系没有正确填充 [英] entity relationship not populating properly
问题描述
Encounter
和 Provider
。 Encounter
实体具有属性 providers ,它是属性$ c的列表$ c>实体,并且没有正确填充。有人可以帮我弄清楚如何解决我的代码,以便实体开始正确填充?
无法正确填充ArrayList的控制器方法的代码如下所示:
@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; $(b
)if(day.equals()){
mydate = new LocalDate();
} else {
mydate = new LocalDate(day);
}
System.out.println(------------------------ in controller,month of month是:+ mydate.getDayOfMonth());
AppointmentCalendar日历=新的AppointmentCalendar(mydate); //或者无论你做什么来创建它
List< Encounter> meettersforday =(List< Encounter>)clinicService.getEncountersForDay(mydate);
model.addAttribute(calendar,calendar);
model.addAttribute(encountersforday,encountersforday);
System.out.println(meettersforday的数量是:+ encountersforday.size());
列表< 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是:+ 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 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; // meetid
filledblocks [g] [2] = 1; // segmentindex
}
}
}
}
返回约会/日历;
System.out.println()
$ b
meettersforday的数量是:5
i,encounterid ,patientid,first,last,numProviders,dateTime是:0,1,5,Peter,McTavish,0,2014-01-10T12:00:00.000-08:00
找到匹配:12:0
i,meetid,patientid,first,last,numProviders,dateTime是:1,2,4,Harold,Davis,0,2014-01-10T11:30:00.000-08:00
找到匹配:11 :30
i,meetid,patientid,first,last,numProviders,dateTime是:2,3,3,Eduardo,Rodriquez,0,2014-01-10T10:00:00.000-08:00找到
匹配在:10:0
i,meetid,patientid,first,last,numProviders,dateTime是:3,4,2,Morticia,Adams,0,2014-01-10T09:30:00.000-08:00
找到匹配:9:30
i,meetid,patientid,first,last,numProviders,dateTime是:4,5,1,Speed,Racer,1,2014-01-10T13:30:00.000- 08:00
找到匹配:13:30
从上面的输出可以看出, Encounter
对象中只有一个大于0 numProviders
。尽管 Encounters
中的每一个都有一个在基础数据表中指定的 Provider
,但这是事实。
注意:为了简化本文,我已将相关代码上传到文件共享网站。您可以点击下面的链接查看文件共享网站上的代码。
您可以阅读用于创建和填充数据表的代码遇到
和提供者
在底层数据库中在此链接。
Encounter
实体的代码是 at this link 。
Provider
实体是在此链接。
BaseEntity
的代码是在此链接。
Person
实体的代码是在此链接。
解决方案每个插入到 providerEncounterJunction
表中的表使用相同的主键。我猜想他们只是简单地相互覆盖,而你只在表格中有一行。
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.
解决方案 Every insert into the providerEncounterJunction
table uses the same primary key. I would guess they are simply overwriting each other and you only really have one row in that table.
这篇关于实体关系没有正确填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!