Last active
December 10, 2015 06:28
-
-
Save maartenl/4394934 to your computer and use it in GitHub Desktop.
An example of the use of @joincolumn in an Entity class to refer to itself.
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
/** | |
* A person. | |
*/ | |
@Entity | |
@Table(name = "mm_usertable", catalog = "mmud", schema = "") | |
public class Person implements Serializable | |
{ | |
@Id | |
@Basic(optional = false) | |
@NotNull | |
@Size(min = 3, max = 20) | |
@Column(name = "name") | |
@Pattern(regexp = NAME_REGEXP, message = "Invalid name") | |
private String name; | |
@ManyToMany(targetEntity = Person.class, fetch = FetchType.LAZY, cascade = | |
{ | |
CascadeType.ALL | |
}) | |
@JoinTable(name = "mm_ignore", joinColumns = | |
{ | |
@JoinColumn(name = "fromperson", referencedColumnName = "name") | |
}, inverseJoinColumns = | |
{ | |
@JoinColumn(name = "toperson", referencedColumnName = "name") | |
}) | |
private Set<Person> ignoringSet; | |
@ManyToMany(mappedBy = "ignoringSet", targetEntity = Person.class, | |
fetch = FetchType.LAZY, cascade = | |
{ | |
CascadeType.ALL | |
}) | |
private Set<Person> ignoredSet; | |
/** | |
* Provides the set of persons that you are ignoring, | |
*/ | |
public Set<Person> getIgnoringSet() | |
{ | |
return ignoringSet; | |
} | |
/** | |
* Provides the set of persons that are ignoring you | |
*/ | |
public Set<Person> getIgnoredSet() | |
{ | |
return ignoredSet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment