Annotation Interface ManyToOne
This annotation also adds the @Transient and
@Value("null") annotations to the field.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionSpecifies the name of the "foreign key" column in the current entity's table.booleanWhether the associated entity persists or not.
-
Element Details
-
foreignKey
String foreignKeySpecifies the name of the "foreign key" column in the current entity's table. This is optional because the annotation can infer the "foreign key" column name in two different ways:1. The column's name matches the parent table's name followed by an
_idsuffix.2. The column's name matches the name of the annotated field followed by an
_idsuffix.For example, given a parent table
country, a child tablecity, and the annotated field@OneToMany Country originCountry;. The "foreign key" column of thecitytable will be inferred as eithercountry_idusing option (1) or asorigin_country_idusing option (2).- Returns:
- the "foreign key" column name
- Default:
""
-
persist
boolean persistWhether the associated entity persists or not. Defaults tofalse.Many-to-one relationships are a backreference of a one-to-many relationship. They are usually expected to be link-only, meaning the parent should exist to link the entity through their
foreignKey(), and no changes are made to the parent entity. Setting this option totruecreates/updates the parent before linking the entity.- Returns:
trueif the associated entity persists,falseotherwise
- Default:
false
-