[
https://issues.apache.org/jira/browse/DELTASPIKE-787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14228121#comment-14228121
]
Thomas Hug commented on DELTASPIKE-787:
---------------------------------------
Hi Wojtek! Apologies, my explanation was too short. The problem in your sample
is the call to the MouseRepository inside the mapper where you resolve the
Mouse with the findBy. Replace the repository there with an injected
EntityManager and get the Mouse with a entityManager.find(Mouse.class,
mouseId). That will fix the NullPointer.
To give you an insight on the internals, calls to repositories keep a
ThreadLocal for call- and repository contextual data (the
QueryInvocationContext). At the end of each call, this ThreadLocal gets cleaned
up. So if you call ComputerRepository, the implementation will create the
ThreadLocal, call the Mapper which calls again MouseRepository. MouseRepository
cleans up the ThreadLocal and it's missing afterwards in ComputerRepository. We
have to stack this ThreadLocal to get rid of the problem.
> NPE in EntityRepositoryHandler for persistent methods of DTO EntityRepository
> -----------------------------------------------------------------------------
>
> Key: DELTASPIKE-787
> URL: https://issues.apache.org/jira/browse/DELTASPIKE-787
> Project: DeltaSpike
> Issue Type: Bug
> Components: Data-Module
> Affects Versions: 1.0.2, 1.0.3, 1.1.0
> Environment: Wildfly 8.1.0.Final/8.2.0.Final, Win7
> Reporter: Wojciech Żaboklicki
> Assignee: Thomas Hug
> Priority: Critical
> Attachments: dto-repository-test.zip
>
>
> NPE when trying to save object (or any other persistent operation) using DTO
> Repository. QueryInvocationContext in EntityRepositoryHandler is not injected.
> Non-persistent operations, like finBy or findAll, work fine. Non-dto entity
> repository persists data correct.
> Piece of stacktrace:
> Caused by: java.lang.NullPointerException
> at
> org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler.save(EntityRepositoryHandler.java:66)
> [deltaspike-data-module-impl-1.1.0.jar:1.1.0]
> Debugger shows that entity provided to the method is correct, that means
> another Repository, used for dto to entity mapping in the same thread, works
> fine.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)