无法实现存储库方法:igenericReactorRePository.Save(对象实体)用于通用存储库

发布于 2025-01-20 08:10:25 字数 1420 浏览 6 评论 0原文

尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城挽邺 2025-01-27 08:10:25

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文