Spring Data Rest中同一实体的多个存储库 [英] Multiple Repositories for the Same Entity in Spring Data Rest

查看:70
本文介绍了Spring Data Rest中同一实体的多个存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Spring Data Rest为同一JPA实体发布两个不同的存储库? 我为这两个存储库指定了不同的路径和相关名称,但是这两个存储库中只有一个可以用作REST端点. 我拥有两个存储库的要点是,其中一个是摘录,仅显示实体的基本字段.

Is it possible to publish two different repositories for the same JPA entity with Spring Data Rest? I gave the two repositories different paths and rel-names, but only one of the two is available as REST endpoint. The point why I'm having two repositories is, that one of them is an excerpt, showing only the basic fields of an entity.

推荐答案

可怕的部分不仅是每个实体只能拥有1个Spring数据存储库(@RepositoryRestResource),而且还有您有一个常规的JPA @Repository(例如CrudRepository或PagingAndSorting),它还将与其余的spring数据交互(因为映射中的键是Entity本身). 浪费了几个小时来调试一个或另一个的随机负载.我猜想,如果这是对spring数据休息的严格限制,那么在尝试覆盖该值时,如果映射的键已经存在,那么至少会引发Exception.

The terrible part is not only that you can only have 1 spring data rest repository (@RepositoryRestResource) per Entity but also that if you have a regular JPA @Repository (like CrudRepository or PagingAndSorting) it will also interact with the spring data rest one (as the key in the map is the Entity itself). Lost quite a few hours debugging random load of one or the other. I guess that if this is a hard limitation of spring data rest at least an Exception could be thrown if the key of the map is already there when trying to override the value.

这篇关于Spring Data Rest中同一实体的多个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆