Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e4ae46d

Browse files
add: Category entity
1 parent bec2e43 commit e4ae46d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.springboot.blog.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
import java.util.List;
10+
11+
@Getter
12+
@Setter
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
16+
@Entity
17+
@Table(name = "categories")
18+
public class Category {
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.IDENTITY)
21+
private long id;
22+
23+
private String name;
24+
private String description;
25+
26+
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
27+
private List<Post> posts;
28+
}

‎src/main/java/com/springboot/blog/entity/Post.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ public class Post {
3636
// post target table -> Comment class field (private Post post)
3737
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
3838
private Set<Comment> comments = new HashSet<>();
39+
40+
@ManyToOne(fetch = FetchType.LAZY)
41+
@JoinColumn(name = "category_id")
42+
private Category category;
3943
}
44+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /