/PostTag.java Secret
Created
August 15, 2019 19:07
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
@Immutable | |
@Entity | |
@Table(name = "post_tag") | |
@Getter | |
@EqualsAndHashCode | |
@NoArgsConstructor | |
public class PostTag { | |
@NoArgsConstructor | |
@AllArgsConstructor | |
@EqualsAndHashCode | |
@Embeddable | |
public static class Id implements Serializable { | |
private static final long serialVersionUID = 1L; | |
@Column(name = "post_id") | |
protected UUID postId; | |
@Column(name = "tag_id") | |
protected UUID tagId; | |
} | |
@EmbeddedId | |
protected PostTag.Id id = new PostTag.Id(); | |
@ManyToOne | |
@JoinColumn(name = "post_id", insertable = false, updatable = false) | |
private Post post; | |
@ManyToOne | |
@JoinColumn(name = "tag_id", insertable = false, updatable = false) | |
private Tag tag; | |
public PostTag(Post post, Tag tag) { | |
this.post = post; | |
this.tag = tag; | |
this.id.postId = post.getId(); | |
this.id.tagId = tag.getId(); | |
post.getPostTags().add(this); | |
tag.getPostTags().add(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment