- Open the desired entity class for editing.
- Type field declaration for a new relationship. For example,
private Product suppliedBy;
- Create getter and setter methods. To do that, press Alt+InsertCommand N; Command Enter,
and select from the suggestion list. For example:
public Product getSuppliedBy() { returnsuppliedBy; } public void setSuppliedBy(Product suppliedBy) { this.suppliedBy = suppliedBy; }
- Annotate the field with the desired relationship annotation, and specify annotation parameters,
if required. For example:
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false, mappedBy = "id")
Note
If a parameter value is a reference to an entity of a data source, IntelliJ IDEA validates these references against the data source mapped in the facet settings.
- In the Persistence tool window, under the desired Hibernate-enabled module,
right-click the desired session factory,
and click
on the toolbar. - In the diagram, select the source entity and draw a link to the target entity.
- In the Create Relationship dialog box, specify the options for the owner and the inverse side of a relationship. Note that if you specify options for one side of a relationship only, it will be created unidirectional. Click OK.
- In the Persistence tool window, under the desired Hibernate-enabled module,
right-click the desired session factory and choose on the context menu.
Tip
You can invoke the same command on the context menu of an entity in the ER diagram.
- In the dialog box that opens, specify the relationship name and type. By default, the entity in question becomes the owner of a relationship. If you want to make it the inverse side, check the Inverse option. Click OK.
Tip
To edit an existing relationship, you can either modify its source code, or double-click the relationship link in Hibernate ER diagram, and change its properties in the dialog box.




