Reputation: 982
I have a little question about spring-data-mongodb:
I have ProductDocument class:
@Document
public @Data class ProductDocument extends DocumentObject {
private String name;
private int category;
private int unit;
private String description;
private double price;
@DBRef
private ProducerDocument producer;
private int unitInStock;
private int status;
private String city;
}
And suppose that I new the class by setting a new ProducerDocument that is not persisted on db.
When I check the product document from db, it is persisted perfectly:
However, new producer object is not persisted to producer collection. I mean if you check the producer id from producer collection, it returns null.
How can I set spring mongodb that if the value is new, add to the referenced collection too.
Thanks.
Upvotes: 0
Views: 1825
Reputation: 6726
Spring Data MongoDB does not cascade operations to referenced objects. Thus there is no configuration option do achieve the desired behaviour. Please see the reference documentation for more information.
Upvotes: 1