Is it possible in Spring Boot using Spring Data JPA to insert an entity with a foreign key without resorting to getting first the foreign entity object?
From what I can do is, I have to first query the Department and use the resulting object as the foreign key object to my Employee entity.
So what's happening is
- findDeptByDept - use that object and store it to currentDept
- use currentDept to Employee object dept setter method (emp.setDept)
- save
I know before hand what dept id is. Actually, I have a list of emps with their corresponding dept id. Is it really necessary to query first the dept object and set that object to emp.setDept(dept)?
Is there away not to do this in hibernate under spring boot and spring data?