AuditorAware implementaion

I have multiple entities where i used @createdBy, @LastModifiedBy etc or spring data. Now this is saving the username column of user. I need to change it to like firstname.lastname.
I found there is one method using implements AuditorAware {

Attaching the code

@Configuration
public class AuditorAwareImpl implements AuditorAware {

@Override
public Optional<String> getCurrentAuditor() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    if (authentication == null || !authentication.isAuthenticated()) {
        return Optional.empty();
    }

    User user = (User) authentication.getPrincipal();
    String auditorName = user.getFirstName().concat(".").concat(user.getUsername());
    return Optional.of(auditorName);
}

}

What i expected is during save the call will reach here to get the value for @createdBy or @LastModifiedBy. But it will reach here only in case of spring data save is what i got from other forums.
Did you have any solution for this
Should we add something in some other places. like some annotaions like @EnableJpaAuditing or something else

Can we use this wihout jpa dependency
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

Thankyou

Jmix audit trait feature doesn’t use AuditorAware from Spring.
You should provide a converter like this one:

package com.company.demo.app;

import com.company.demo.entity.User;
import io.jmix.data.impl.converters.AuditConversionService;
import io.jmix.data.impl.converters.AuditConversionServiceImpl;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.convert.converter.Converter;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

@Component
public class MyUserToStringConverter implements Converter<UserDetails, String> {

    private final AuditConversionService auditConversionService;

    public MyUserToStringConverter(AuditConversionService auditConversionService) {
        this.auditConversionService = auditConversionService;
    }

    @Override
    public String convert(UserDetails source) {
        if (source instanceof User user) {
            return user.getFirstName() + "." + user.getLastName();
        } else {
            return source.getUsername();
        }
    }

    @EventListener
    public void onApplicationContextRefreshed(final ContextRefreshedEvent event) {
        ((AuditConversionServiceImpl) auditConversionService).addConverter(this);
    }
}