Skip to content

Instantly share code, notes, and snippets.

@Tonel
Last active July 4, 2020 10:59
Show Gist options
  • Save Tonel/d0174f79df2ae4fc4f826e2800bb50ac to your computer and use it in GitHub Desktop.
Save Tonel/d0174f79df2ae4fc4f826e2800bb50ac to your computer and use it in GitHub Desktop.
@Entity
@Table(name = "post")
data class Post(
@get:Id
@get:GeneratedValue
@get:Column(name = "id")
val id: Long,
@get:Column(name = "title")
val title: String,
@get:ManyToMany
@get:JoinTable(
name = "post_tag",
joinColumns = [JoinColumn(name = "post_id")],
inverseJoinColumns = [JoinColumn(name = "tag_id")]
)
val tags: Set<Tag> = HashSet()
)
@Entity
@Table(name = "tag")
data class Tag(
@get:Id
@get:GeneratedValue
@get:Column(name = "id")
val id: Long,
@get:Column(name = "name")
val name: String,
@get:ManyToMany(mappedBy = "tags")
val posts: Set<Post> = HashSet()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment