Created
July 13, 2018 05:53
-
-
Save mohamed-gara/cb6c8b1160abe62b6c022ced07234d75 to your computer and use it in GitHub Desktop.
Person with partner relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@Data | |
public class Person extends core.Person { | |
@OneToOne(fetch = LAZY) | |
private Person wife; | |
@OneToOne(fetch = LAZY, mappedBy = "wife") | |
private Person husband; | |
public Person getPartner() { | |
if ((wife != null) && (husband != null)) throw new IllegalStateException(); | |
if (wife != null) return wife; | |
if (husband != null) return husband; | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment