Last active
October 11, 2019 14:17
-
-
Save jrichardsz/61107987b8b0d55e9ba523aad31f51cc to your computer and use it in GitHub Desktop.
jpa snippets
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 | |
public class Organization extends GenericEntity { | |
@Column(length = 50) | |
@Required | |
private String name; | |
@Column(length = 50) | |
@Required | |
private String description; | |
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) | |
@JoinTable(name = "organization_application", joinColumns = @JoinColumn(name = "organization_id"), inverseJoinColumns = @JoinColumn(name = "aplication_id")) | |
private Set<Application> applications = new HashSet<>(); | |
@Entity | |
public class Application extends GenericEntity { | |
@Column(length = 50) | |
@Required | |
private String name; | |
@Column(length = 50) | |
@Required | |
private String description; | |
@Column | |
@Required | |
private boolean disabled = false; | |
@ManyToMany(mappedBy = "applications") | |
private Set<Organization> organizations = new HashSet<>(); |
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 | |
public class Application extends GenericEntity { | |
@Column(length = 50) | |
@Required | |
private String name; | |
@Column(length = 50) | |
@Required | |
private String description; | |
@Column | |
@Required | |
private boolean disabled = false; | |
@ManyToOne(fetch = FetchType.LAZY) | |
@JoinColumn(name = "organization_id") | |
private Organization organization; | |
@Entity | |
public class Organization extends GenericEntity { | |
@Column(length = 50) | |
@Required | |
private String name; | |
@Column(length = 50) | |
@Required | |
private String description; | |
@OneToMany(mappedBy = "organization", cascade = CascadeType.ALL, orphanRemoval = true) | |
private List<Application> applications = new ArrayList<Application>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment