I'm encountering a problem in my Spring Boot application when I use the @EnableMongoAuditing annotation.
The application throws a NullPointerException that seems to be related to the auditing mechanism. Interestingly, the issue disappears when I remove the @EnableMongoAuditing
annotation, but I'd like to use auditing in my application.
Here's the relevant entity class that I'm working with:
import ..*.model.ContractOverdue;
import *.model.Overdue;
import lombok.Builder;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashMap;
@Builder
@Data
@Document(collection = "contract-overdue")
public class MGReceiptContractOverdue {
@Id
private String id;
private String contractRef;
private HashMap<String, HashMap<Integer, Overdue>> overdueList;
// Constructor and methods...
}
I don't have any auditing-related fields in my entity class, and the issue only arises when the @EnableMongoAuditing annotation is present in the configuration.
Here's a part of the stack trace of the error:
Caused by: java.lang.NullPointerException: null
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.from(PersistentPropertyPathFactory.java:266) ~[spring-data-commons-2.6.3.jar:2.6.3]
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.lambda$from$2(PersistentPropertyPathFactory.java:262) ~[spring-data-commons-2.6.3.jar:2.6.3]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360) ~[spring-data-commons-2.6.3.jar:2.6.3]
What could be causing this issue, and how can I use the @EnableMongoAuditing annotation without encountering a NullPointerException? Any guidance or suggestions would be greatly appreciated.
Thank you in advance for any help!