Skip to content

Instantly share code, notes, and snippets.

@artemptushkin
Last active May 25, 2020 09:40
Show Gist options
  • Save artemptushkin/fd8934459ede1b4d01618815a93f656f to your computer and use it in GitHub Desktop.
Save artemptushkin/fd8934459ede1b4d01618815a93f656f to your computer and use it in GitHub Desktop.
Hibernate NPE on delete events
@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