我試圖使用RepositoryRestResource
和RestTemplate
熱切加載的MongoDB @DBRef在Spring數據的RepositoryRestResource
的所有作品,而是很好地實現一個REST API,除了裝載@ DBREF的
考慮這個數據模型:
public class Order
{
@Id
String id;
@DBRef
Customer customer;
... other stuff
}
public class Customer
{
@Id
String id;
String name;
...
}
和下面的存儲庫(類似一個客戶)
@RepositoryRestResource(excerptProjection = OrderSummary.class)
public interface OrderRestRepository extends MongoRepositor<Order,String>{}
的REST API返回以下JSON:
{
"id" : 4,
**other stuff**,
"_links" : {
"self" : {
"href" : "http://localhost:12345/api/orders/4"
},
"customer" : {
"href" : "http://localhost:12345/api/orders/4/customer"
}
}
}
其若被resttemplate將創造客戶新訂購的實例= NULL正確加載
是否有可能急切地解決客戶對信息庫結束並嵌入JSON?
我使用嵌套投影來修復它。這像一個魅力。由於我只需要在檢索單個訂單時進行急切的解決,所以查詢量將會很小。謝謝! –