curena
8/16/2016 - 4:48 PM

Unidirectional OneToMany relationship in JPA

Unidirectional OneToMany relationship in JPA

The Owner (The "many" side):
@Id
@Column(name="Id")
private Long id;
  
@Column(name = "ProductId", insertable = false, updatable = false)
private Long productId;

The "One" side:

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "ProductId", referencedColumnName = "Id", nullable = false)
private List<Thing> things = new ArrayList<>();