Annotation Interface OneToMany
This annotation also adds the @Transient and
@Value("null") annotations to the field.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether orphan entities are preserved or not.booleanWhether children entities are only linked to the parent or not.Specifies the name of the "foreign key" column on the child table.booleanWhether the children entities are read-only or not, meaning they are never persisted or linked to the parent.Specifies the column used to sort the populated children entities.org.springframework.data.domain.Sort.DirectionSpecifies in which direction the populated children entities are sorted.
-
Element Details
-
keepOrphans
boolean keepOrphansWhether orphan entities are preserved or not. Defaults tofalse.Usually, one-to-many relationships have a parent-children configuration, meaning every child needs a parent assigned to it. By default, the annotation will delete orphan entites, or children which are no longer assigned to their parent. You can prevent this behavior by setting this option to
true, in which case the annotation will only remove the link of the orphan entities with the parent.- Returns:
trueif orphan entities should be presereved,falseotherwise
- Default:
false
-
linkOnly
boolean linkOnlyWhether children entities are only linked to the parent or not. Defaults tofalse.Link-only means the children entities should already exist. The annotation will only update the "foreign key" link on each entity when required. Other values in the children entities are never updated.
- Returns:
trueif children entities are only linked,falseotherwise
- Default:
false
-
mappedBy
String mappedBySpecifies the name of the "foreign key" column on the child table. This is optional if the column's name matches the parent's table name followed by an_idsuffix.For example, given a parent table
countryand a child tablecity, the "foreign key" column of thecitytable will be inferred ascountry_id.- Returns:
- the "foreign key" column name in the child table
- Default:
""
-
readonly
boolean readonlyWhether the children entities are read-only or not, meaning they are never persisted or linked to the parent. Defaults tofalse.- Returns:
trueif the children entities are read-only,falseotherwise
- Default:
false
-
sortBy
String sortBySpecifies the column used to sort the populated children entities.By default, the annotation tries to find the field associated with
Auditable.getCreatedDate()or annotated with@CreatedDate. If none can be found, it'll try to find a"created_at"column as a last resort. If all of that fails, the children will be unsorted.- Returns:
- the sorting column name
- Default:
""
-
sortIn
org.springframework.data.domain.Sort.Direction sortInSpecifies in which direction the populated children entities are sorted. Defaults toSort.Direction.DESC.- Returns:
- the sort direction
- Default:
DESC
-