Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name="posts_post",
- indexes = { @Index(name = "created", columnList = "created"),
- @Index(name = "updated", columnList = "updated"),
- @Index(name = "slug", columnList = "slug"),},
- uniqueConstraints = {
- @UniqueConstraint(name = "slug_unique_constraint", columnNames= "slug"),
- })
- @Getter
- @Setter
- @NoArgsConstructor
- public class PostEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- @CreationTimestamp
- @Column(nullable = false)
- private LocalDateTime created;
- @UpdateTimestamp
- @Column(nullable = false)
- private LocalDateTime updated;
- @Column(nullable = false, columnDefinition = "TEXT")
- private String text;
- @Column(nullable = false)
- private String slug;
- @ManyToOne
- @JoinColumn(foreignKey=@ForeignKey(name="AUTHOR_POSTS_FK"), nullable = false)
- private AuthorEntity author;
- @ManyToOne
- @JoinColumn(foreignKey=@ForeignKey(name="CATEGORY_POSTS_FK"), nullable = false)
- private CategoryEntity category;
- public PostEntity(String slug,
- String text,
- AuthorEntity author,
- CategoryEntity category) {
- this.slug = slug;
- this.text = text;
- this.author = author;
- this.category = category;
- }
- }
- blog=# \d posts_post
- Table "public.posts_post"
- Column | Type | Collation | Nullable | Default
- -------------+-----------------------------+-----------+----------+----------------------------------
- id | integer | | not null | generated by default as identity
- created | timestamp without time zone | | not null |
- slug | character varying(255) | | not null |
- text | text | | not null |
- updated | timestamp without time zone | | not null |
- author_id | integer | | not null |
- category_id | integer | | not null |
- Indexes:
- "posts_post_pkey" PRIMARY KEY, btree (id)
- "created" btree (created)
- "updated" btree (updated)
- Foreign-key constraints:
- "author_posts_fk" FOREIGN KEY (author_id) REFERENCES authors_author(id)
- "category_posts_fk" FOREIGN KEY (category_id) REFERENCES categories_category(id)
Advertisement
Add Comment
Please, Sign In to add comment