无法实现存储库方法:igenericReactorRePository.Save(对象实体)用于通用存储库
尝试使用MongoDB和Microanaut数据创建通用存储库。
@MongoRepository
public interface IGenericReactorRepository<E, ID> extends ReactorCrudRepository<E, ID> { }
我已定义的
@Singleton
public record VendorService(IGenericReactorRepository<Vendor, ObjectId> iGenericReactorRepository) implements IVendorService {
@Override
public Flux<FindVendorModel> find(VendorFilterModel searchCriteria) {
return Flux.just(findVendorModel);
}
}
实体类型和objectId igenericReaCtorRepository&lt; vendor,ObjectId&gt; gt; igenericReactorRepository
。问题是在接口上的@mongorepository
注释,它创建了以下例外,
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')
我不想在下面
@MongoRepository
public interface IGenericReactorRepository extends ReactorCrudRepository<Vendor, ObjectId> { }
使用此方法创建类似的内容,我需要为每个实体创建一个单独的接口。我该如何制作这个通用?因此,在依赖注入中,我只是通过实体和键入public Record vendorService(igenericReaCtorreRepository&lt; vendor,objectId&gt; igenericreactorreposority)
。
有什么解决方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Micronaut数据需要在编译时知道实际实体,以生成可能的查询。 MongoDB集成不需要太多的预生成的查询,例如SQL支持,但这就是现在的工作方式。也许我们可以提供另一种方式来访问API操作不受存储库的API操作。
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.