春の dbref 関数を使用しようとしています。
私のコード:
@EnableAutoConfiguration
@RestController
@RequestMapping("/poi")
public class PoiBasicController {
@Autowired
private PoiRepository poiRepository;
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<String> add(@RequestBody PointOfInterest poi) {
poiRepository.insert(poi);
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@EnableAutoConfiguration
@RestController
@RequestMapping("/tour")
public class TourController {
@Autowired
private TourRepository tourRepository;
@Autowired
private PoiRepository poiRepository;
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<String> addTour(@RequestBody Tour tour) {
tourRepository.insert(tour);
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@Document
public class Tour {
@Id
private String id;
private HashMap<String, String> title;
private HashMap<String, String> description;
private List<String> images;
@DBRef(db = "pois")
private List<PointOfInterest> poiList;
@Document(collection = "pois")
public abstract class PointOfInterest {
@Id
private String id;
private UpperCategory upperCategory;
private List<String> tags;
private int priority;
private List<String> images;
private LocationWrapper location;
/*
Languagekey, description
*/
private HashMap<String, String> description;
Poi クラスは、さまざまなタイプの poi (Culture など) によって実装されます。Tour オブジェクトの pois をリストとして参照したい。
pois コレクションに poi を保存するために POST を実行します。
問題: poi オブジェクトの objectID-reference を使用してツアーで POST を実行すると、ツアーの poi List が常に null になります。
@DBRef は正しく理解しましたね。
Edit1: エラーメッセージ
問題は次のとおりです。「poi_id_1」と「poi_id_2」で参照されるデータベースに 2 つの pois があるとします。ここで、次の JSON 配列を使用して /tour/add への API 呼び出しを開始します (他の引数は省略します)。
"poiList": [{"id": "poi_id_1"}, {"id":"poi_id_2"}]
私は200を取得します。
BUT:ツアーでクエリを開始すると"poiList": [null]
、結果が得られます。(その他の引数は省略)
事前にご協力いただきありがとうございます:)