0

I am using JHIPSTER 3.8.0, although there is a method using @Transactional I saw that there was no log: logging.level.org.springframework.transaction.interceptor = TRACE

Any idea?

EDIT

...
@Repository
public class CustomAuditEventRepository implements AuditEventRepository {

    private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";

    private final PersistenceAuditEventRepository persistenceAuditEventRepository;

    private final AuditEventConverter auditEventConverter;

    public CustomAuditEventRepository(PersistenceAuditEventRepository persistenceAuditEventRepository,
            AuditEventConverter auditEventConverter) {

        this.persistenceAuditEventRepository = persistenceAuditEventRepository;
        this.auditEventConverter = auditEventConverter;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void add(AuditEvent event) {
        if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
            !Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {

            PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
            persistentAuditEvent.setPrincipal(event.getPrincipal());
            persistentAuditEvent.setAuditEventType(event.getType());
            persistentAuditEvent.setAuditEventDate(event.getTimestamp());
            Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
            persistentAuditEvent.setData(truncate(eventData));
            persistenceAuditEventRepository.save(persistentAuditEvent);
        }
    }

    private Map<String, String> truncate(Map<String, String> data) {
        ....
    }
}

CONFIGURATIONS:

-> jhipsterVersion: "6.9.1"

-> databaseType: "mongodb"

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
Adam D
  • 85
  • 2
  • 2
  • 9
  • Are you calling the (public) method from another class through its interface or are you calling the method from within the class itself? The latter won't work, as it does not go through the proxy. – knittl Aug 13 '22 at 19:24
  • I am calling the method from another class. And the method is public. Be aware that there is already a method generated by Jhipster with @Transactional. – Adam D Aug 13 '22 at 19:31
  • When I want to see transactions I use this logger "org.springframework.transaction" and it works in JHipster apps, what makes you think you should use "org.springframework.transaction.interceptor"? Does it make any difference? – Gaël Marziou Aug 13 '22 at 22:01
  • Hi @GaëlMarziou, when I use logger "org.springframework.transaction", it doesn't make a difference at all. – Adam D Aug 14 '22 at 07:15
  • 1
    Is the class that contains this method a Spring bean? For example, is it annotated with `@Service` or is it instantiated by configuration code? Please show some code. – Gaël Marziou Aug 14 '22 at 08:46
  • @GaëlMarziou, I just updated the post. – Adam D Aug 14 '22 at 12:35
  • Sorry I know nothing about MongoDb and your tags did not mention it either, I just added it here because it's very important. I won't be of any help here. Have you read this? https://stackoverflow.com/questions/55087184/does-spring-transactional-work-with-mongodb – Gaël Marziou Aug 14 '22 at 18:57
  • Yes, I have already seen this post but I wanted to use the Spring dependency independent of the database. In any case, thank you for your help. – Adam D Aug 15 '22 at 08:03

0 Answers0