0

What is the best way to set an dbRef in entity? I would not save a relation as embedded object in a collection for example.

public class Order {

    @Id
    @GeneratedValue
    public String id;

    private List<Article> articles;
}

public class Article {

    @Id
    @GeneratedValue
    public String id;

    private String name;
}
abuder
  • 1,030
  • 2
  • 13
  • 31

1 Answers1

0

Jongo save relations as embedded document.

If you realy want's dbRef instead, you'll have to deal it by yourself.

public class Order {

    @Id
    @GeneratedValue
    public String id;

     // _id of articles
     private List<String> articles;
}

When you'll save an Order, you'll have to save Articles, then update your Order.

dwursteisen
  • 11,435
  • 2
  • 39
  • 36