I got NPE when trying to call getter. It is a @OneToMany mapped property. It works when I call via other than the current object.
It is not working for the below code.
@PostMapping("/updateservice")
public void updateService(@ModelAttribute ServiceTyping serviceTyping, BindingResult bindingResult, HttpServletRequest req, HttpServletResponse res) throws IOException {
if(serviceTyping.getServiceEntryAttributes().containsKey(ServiceConstants.outsourcer)) {
LOG.info("**INFO OUTSOURCER FOUND*******");
}
}
But working when I accessed from other object
@PostMapping("/updateservice")
public void updateService(@ModelAttribute ServiceTyping serviceTyping, BindingResult bindingResult, HttpServletRequest req, HttpServletResponse res) throws IOException {
ServiceTyping st = entryService.findTypingEntryById((long) 194);
if(st.getServiceEntryAttributes().containsKey(ServiceConstants.outsourcer)) {
LOG.info("**INFO OUTSOURCER FOUND*******");
}
}
I tried with hot-coding below code, I mean directly pass the current object's id. It also doesn't work.
@PostMapping("/updateservice")
public void updateService(@ModelAttribute ServiceTyping serviceTyping, BindingResult bindingResult, HttpServletRequest req, HttpServletResponse res) throws IOException {
//here 176 is the id of the entity
ServiceTyping st = entryService.findTypingEntryById((long) 176);
//checking the object which has the 176 is found are not
if(entryService.findEntryById((long) 176)!=null) {
LOG.info("**INFO OBJECT FOUND*******");
if(entryService.findEntryById((long) 176).getServiceEntryAttributes().containsKey(ServiceConstants.outsourcer)) {
LOG.info("**INFO OUTSOURCER FOUND*******"); }
}
}
I'm not saying it is not working for the particular id 176. It doesn't working for any other objects. but it works in the case when I access through the object other than the same object found in
public void updateService(@ModelAttribute ServiceTyping serviceTyping)
From the code and attached table, I have proven two things. 1) the object through which I try to access is not null; 2) the value which I trying to get is found and it is also not null.
Let me know if I'm confusing