@ManyToOne maps a unidirectional association in which multiple source entities reference one target entity. A foreign-key column in the source table stores the target identifier; the association can stand alone without a mapped collection on the target. section 8.3.1
Configure the association by combining the required annotation with optional constraints and loading settings:
- Place @ManyToOne on the source property, such as Bid.item. section 8.3.1
- Use @JoinColumn to name the foreign-key column or make it NOT NULL; alternatively, use optional = false or @NotNull for non-nullability. section 8.3.1
- Treat @ManyToOne as the owning side when the relationship is bidirectional; @OneToMany provides the mappedBy side. section 9.2.2
Bid referencing an Item
A Bid can require an Item through a non-null join column: @ManyToOne(fetch = FetchType.LAZY), followed by @JoinColumn(name = "ITEM_ID", nullable = false). Calling someBid.getItem() dereferences the association, while a JPQL query such as select b from Bid b where b.item = :itemParameter retrieves an Item's bids.
For ordered one-to-many collections, the @ManyToOne side still controls the join column and generated schema. In an embeddable link component, multiple @ManyToOne associations can instead form a ternary relationship, but the embeddable cannot provide bidirectional navigation. section 9.2.2 section 9.3.3
