San Jaisy
San Jaisy

Reputation: 17128

Unable to implement Repository method: IGenericReactorRepository.save(Object entity) for generic repository

Try to create a generic repository with MongoDb and Microanaut Data.

@MongoRepository
public interface IGenericReactorRepository<E, ID> extends ReactorCrudRepository<E, ID> { }

The implementation of IGenericReactorRepository

@Singleton
public record VendorService(IGenericReactorRepository<Vendor, ObjectId> iGenericReactorRepository) implements IVendorService {
    @Override
    public Flux<FindVendorModel> find(VendorFilterModel searchCriteria) {
        return Flux.just(findVendorModel);
    }
}

In the record parameter I have defined entity type and objectId IGenericReactorRepository<Vendor, ObjectId> iGenericReactorRepository. The issue is with the @MongoRepository annotation on the interface and it creates the below exception

Unable to implement Repository method: IGenericReactorRepository.save(Object entity). class com.sun.tools.javac.code.Type$TypeVar cannot be cast to class javax.lang.model.element.Element (com.sun.tools.javac.code.Type$TypeVar is in module jdk.compiler of loader 'app'; javax.lang.model.element.Element is in module java.compiler of loader 'platform')

I don't want to create something like below

@MongoRepository
public interface IGenericReactorRepository extends ReactorCrudRepository<Vendor, ObjectId> { }

With this approach, I need to create a separate interface for each entity. How can I make this generic? So that in dependency injection I just pass the entity and type as like this public record VendorService(IGenericReactorRepository<Vendor, ObjectId> iGenericReactorRepository).

Is there any workaround for this?

Upvotes: 0

Views: 199

Answers (1)

Denis
Denis

Reputation: 613

Micronaut Data need to know the actual entity at the compile-time to generate possible queries. The MongoDB integration doesn't need so many pre-generated queries like SQL support but that's how it works right now. Maybe we can provide a different way to access Criteria API operations not bound to the repository.

Upvotes: 2

Related Questions