Morphia Entity
クラスのArrayListの継承された@Embedded
参照を使用しています。morphiaのArrayListから特定の要素を削除するにはどうすればよいですか?
@Entity
public class First {
@Embedded private List<Second> secondClass;
private String title;
private Long id;
... getter and setter .. methods
}
@Embedded
public class Second {
@Embedded private List<Third> thirdClass;
private String titleSecond;
... getter and setter .. methods
}
@Embedded
public class Third {
private String titleThird;
private String logoUrl
... getter and setter .. methods
}
JSON
{
"secondClass": [{
"thirdClass": [{
"titleThird": "Java",
"logoUrl": "http://www.artsfon.com/pic/201510//artsfon.com-72885.jpg",
}, {
"titleThird": "ios",
"logoUrl": "http://www.artsfon.com/pic//1920x1080/artsfon.com-72885.jpg",
}],
"titleSecond": "Developer"
}],
"title": "Software Developer",
"id" : 1234567890
}
titleSecond
とid
の与えられた値を持つ要素を削除する方法の質問
1)?
2)指定された値titleThird
とid
の要素を削除するにはどうすればよいですか?
は、最初のために私は次の実装しようとした:
UpdateOperations<First> ops;
Query<First> updateQuery = datastore.createQuery(First.class).filter("id", Long.parseLong(id.trim()));
ops = datastore.createUpdateOperations(First.class).disableValidation().removeAll("secondClass.titleSecond", "Developer");
datastore.update(updateQuery, ops);
をマッピングエラーを投げています:
Write failed with error code 16837 and error message 'cannot use the part (secondClass of secondClass.titleSecond) to traverse the element.
私は質問1と2のためのアクションを実行できますか?どんな助けにも感謝します。
おそらくリンク質問:このようなIn Morphia how can i update one embedded Object inside an ArrayList
最初にこのドキュメントをどのように作成しましたか?レコードを第3のクラスにプッシュできましたか?別の質問。第二のクラスはどのように第三のクラスに結びついていますか?第3クラスを第2クラスと同じレベルに移動できますか? – Veeram
*最初にこの文書をどのように作成したのか不思議です*私は上記の 'JSON'オブジェクトを渡して' datastore.save(firstObject) 'で保存しています。 *レコードを第3クラスにプッシュできました*:はい、レコードを「MongoDB」で見ることができます。 *第2クラスは第3クラスにどのように結びついていますか*:私は 'Second Class'で' @Embedded private List thirdClass; 'を使用しました。投稿されたJSON( '" thirdClass ":[{...}]')をチェックしてください。あなたはすべての質問をクリアしてもらえますか? –
実際には初めての節約ではなく、私の質問は既存のオブジェクトの3番目のクラスに新しいエントリを追加したいのですが、それは試したものですか? – Veeram