-
Notifications
You must be signed in to change notification settings - Fork 9
RelMongo Cascading
When an operation is performed on an document, then it will be performed on that particular document only and not on the documents that are related to it. To be able to propagate the operation, RelMongo provides the io.github.kaiso.relmongo.annotation.CascadeType enumerated types that define the cascade operations. These cascade operation can be defined with any type of mapping i.e. OneToOne, OneToMany.
RelMongo provides two types of cascading operations:
Type | Description |
---|---|
PERSIST |
In this cascade operation, if the parent document is persisted then all its related documents will also be persisted. |
REMOVE |
In this cascade operation, if the parent document is removed then all its related document will also be removed. |
The cascade persist defines the fact that if the parent document is persisted then all the child related documents are also persisted. Note that if the related child document has no id ( does not exist in the database) it will be created and automatically linked to the parent document by RelMongo
The cascade PERSIST is used with the following syntax:
@OneToMany(cascade=CascadeType.PERSIST)
The cascade remove defines the fact that if the parent document is removed then all the child related documents are also removed.
The cascade REMOVE is used with the following syntax:
@OneToMany(cascade=CascadeType.REMOVE)
IMPORTANT ! Be carefull when using cascade REMOVE because in MongoDB there is no integrity constraints so the object you remove by cascading operations may still be referenced in another collection
© Copyright Kais OMRI under the Apache License 2.0