Last active
May 25, 2020 09:40
-
-
Save artemptushkin/fd8934459ede1b4d01618815a93f656f to your computer and use it in GitHub Desktop.
Hibernate NPE on delete events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void hibernate() throws Exception { | |
UUID id = fromString("b80db28f-2e4f-4d18-bb96-6bc5b9b387cb"); | |
EntityManager entityManager = entityManagerProvider.get(); | |
ObjectMapper objectMapper = new ObjectMapper(); | |
doAnswer(new Answer<Void>() { | |
@Override | |
public Void answer(InvocationOnMock invocation) throws Throwable { | |
Object[] args = invocation.getArguments(); | |
EventEntity<?> entity = (EventEntity<?>) args[0]; | |
objectMapper.writeValueAsString(entity); | |
return null; | |
} | |
}).when(eventPublisher).publish(any(EventEntity.class)); | |
CardPlan cardPlan = entityManager.find(CardPlan.class, id); | |
entityManager.remove(cardPlan); | |
assertFalse(entityManager.contains(cardPlan)); | |
entityManager.flush(); | |
verify(eventPublisher, times(1)).publish(any(EventEntity.class)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment