Not able to get and persist data in to data base using swagger api doc with spring boot and tables having onetomany relationship?
Not able to get and persist data in to data base using swagger api doc with spring boot and tables having onetomany relationship?
Below is controller code:
@RequestMapping(value="/empId" ,method=RequestMethod.GET)
ResponseEntity<Employee> getEmpById(@PathVariable("empId") Integer empId)
Employee emp=null;
try
emp=empService.getEmpById(empId);
log.debug("employee_controller - getting employee of id...."+empId);
catch(Exception e)
log.error("employee_controller - error occured while getting employee" +e);
return new <>(emp,HttpStatus.OK);
Below is Service code:
public Employee getEmpById(Integer empId)
Employee emp = null;
try
log.debug("Employee_Service - getting employee by id..." + empId);
emp = empDao.findOne(empId);
System.out.println("emp data is========" + emp);
catch (Exception e)
log.error("Employee_Service - errror occured during getting employee of id" + empId);
return emp;
emphasized text :Getting null while getting and even not able to persist data if tables
having ontomany relation.If i remove relation woring fine.
InputType
stacktrace
**Hibernate:
select
employee0_.empid as empid1_1_1_,
employee0_.empname as empname2_1_1_,
dept1_.empid as empid3_0_3_,
dept1_.deptid as deptid1_0_3_,
dept1_.deptid as deptid1_0_0_,
dept1_.deptname as deptname2_0_0_,
dept1_.empid as empid3_0_0_
from
emp_tbl employee0_
left outer join
dept dept1_
on employee0_.empid=dept1_.empid
where
employee0_.empid=?
2018-09-13 15:22:58 - binding parameter 1 as [INTEGER] - 1
Hibernate:
insert
into
emp_tbl
(empid, empname)
values
(null, ?)
2018-09-13 15:22:58 - binding parameter 1 as [VARCHAR] - [john]
Hibernate:
select
dept0_.deptid as deptid1_0_1_,
dept0_.deptname as deptname2_0_1_,
dept0_.empid as empid3_0_1_,
employee1_.empid as empid1_1_0_,
employee1_.empname as empname2_1_0_
from
dept dept0_
left outer join
emp_tbl employee1_
on dept0_.empid=employee1_.empid
where
dept0_.deptid=?
2018-09-13 15:22:58 - binding parameter 1 as [INTEGER] - [2]
2018-09-13 15:22:58 - Employee_Service - errror occured during saving employeecom.hcl.ontToManyWithH2.Entities.Employee@799f9b7c
2018-09-13 15:22:58 - employee_controller - saving employeecom.hcl.ontToManyWithH2.Entities.Employee@799f9b7c
**
@Casper:getting null value i debugged
– John
Sep 13 '18 at 9:29
So no exception?
– Casper
Sep 13 '18 at 9:29
Null pointer exp
– John
Sep 13 '18 at 9:30
It could help if you copy the whole stack trace and paste it in your question.
– Casper
Sep 13 '18 at 9:31
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Could you add the exception to your question?
– Casper
Sep 13 '18 at 9:26