Created
April 11, 2018 21:45
-
-
Save snekse/662ede7de0b716279977d1702fd13c3f to your computer and use it in GitHub Desktop.
When you have a "child" table that, for whatever reason, only has a single real column in it, then you can use `ElementCollection` for the mapping to avoid some of the hassle w/ creating a real entity and repo. This is especially useful when using Spring Data Rest and you want to be able to easily add/edit/delete the values in this association.
This file contains hidden or 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
//All of the fancy annotations are mostly here if you want to generate the DDL via Hibernate | |
@Size(min = 10) // If you want to limit the max size of the array | |
@ElementCollection(fetch = FetchType.EAGER) | |
@CollectionTable(name = 'IssueRequestor', joinColumns = [@JoinColumn(name = 'IssueID')], | |
uniqueConstraints = [ @UniqueConstraint(name = 'IssueRequestor_uc_issueId_requestor', | |
columnNames = ['IssueID', 'requestor'])]) | |
@Column(name = 'requestor', length = 150) | |
Set<String> requestors = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment