I have a HttpBasic
authentication mechanism in my project and I added the AuthenticationSuccessEvent
handler to it. When I wire entityManager
into my AuthenticationEvents
class and persist entity, EntityManager
doesn’t do anything. I tried to use Spring data crudRepository
but nothing changed.
I replaced entityManager
and used Jdbc
. it’s work!
Can anyone explain to me why entityManager
doesn’t persist anything and even doesn’t log SQL-generated insert
.
@Component
public class AuthenticationEvents {
private final EntityManager entityManager;
public AuthenticationEvents(EntityManager entityManager) {
this.entityManager = entityManager;
}
@EventListener
@Transactional
public void onSuccess(AuthenticationSuccessEvent success) {
AuthenticationAudit audit = new AuthenticationAudit();
audit.setTime(LocalDateTime.now());
entityManager.persist(audit); //it doesn't persist it
}
}