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
@transactionalkeepentitymanageropen , loaded instances eligible lazy-loading pull data out of store while use instance. if controller or service not enough, might wannaopenentitymanagerinviewfilter/-interceptorkeepsentitymanageropen 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
Post a Comment