I would like to have a One-to-many relationship between 2 Entities, Consumer and Policy. One consumer should have several policies.
This is an example of a Consumer JSON object I would like to have:
{
id : 1,
name : "Peter",
endpoint: "123.456.778",
policies: [
{
id : 1,
name: "policy 01"
},
{
id : 2,
name: "policy 02"
}
]
}
This is what I have so far:
Policy Entity
@Entity
public class Policy {
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
//getters and setters
}
Consumer Entity
@Entity
public class Consumer {
@Id
@GeneratedValue
@Column(name = "consumer_id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "endpoint")
private String endpoint;
@OneToMany
@JoinColumn(??)
private List<Policy> policies;
//getters and setters
}
It's not that hard I think, but im trying now for several hours and can't get it done. I'm new to Spring, so if someone is able to help me, I would be very thankfull!