Unlucky
Unlucky

Reputation: 173

Spring data - two one to many relationships

is there a way to have one entity (ex. Place ) bounded with another entity (ex. order ) where there are two "places" source and destination ?

example code :

@NotNull
@JoinColumn(name = "SOURCE_ID")
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.PERSIST)
private Place source;

@NotNull
@JoinColumn(name = "DESTINATION_IDs")
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.PERSIST)
private Place destination;

What will be on the Place entity?

Upvotes: 0

Views: 40

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81998

This will work without a problem just like single relations. There is no difference. This includes making the relationship bidirectional, although I'm almost always skeptical about bidirectional relationships.

Upvotes: 1

Related Questions