dimanche 19 juin 2022

How does MongoRepository finds the correct collection when findById(String id) is called?

I'm trying to understand a little more about how does Spring finds the correct Collection when calling the findById(String id) method. Normally the classes that will be persisted are annotated with @Document(collection = "CollectionName") and when a basic operation like:

T save(T entity);
Optional<T> findByExample(T entity);
T update(T entity);

Seem kinda understandable that we can access the annotation data since we have the whole entity available, but when a method like:

T findById(String id)

We don't have access to the entity information, the closer we get is the Generic type T. But only with the type T we are not able to initialize a new object and get the annotations information. There is any documentation available that explains this?





Aucun commentaire:

Enregistrer un commentaire