Why are my entities only partially populated when loading them using Spring Data JPA? -


i'm using spring data jpa , datanucleus jpa persistence provider , have

interface bookrepository extends crudrepository<book, long> {     book findbyauthorid(long id); } 

if call bookrepository.findbyauthorid() , access book.publishinghouse.manager.name null. opposed calling bookrepository.findall() when fields populated correctly way. set datanucleus.detachalloncommit=true , datanucleus.maxfetchdepth=-1 (i tried 10).

any idea why?

if don't have additional transaction boundaries defined, entitymanager closed when leaving query method. means detached entities , kind of load state determined defaults persistence provider uses.

you have 2 options:

  • have client (service or controller class) using @transactional keep entitymanager open , loaded instances eligible lazy-loading pull data out of store while use instance. if controller or service not enough, might wanna openentitymanagerinviewfilter/-interceptor keeps entitymanager open until view rendered.

  • define should fetched explicitly either using jpa 2.1 entity graphs (see reference docs details) or explicitly adding fetch-joins query defining manually.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -