Skip to content

Instantly share code, notes, and snippets.

@snekse
Created April 11, 2018 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snekse/662ede7de0b716279977d1702fd13c3f to your computer and use it in GitHub Desktop.
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.
//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