Skip to content

Commit 6f5b75c

Browse files
committed
modify post and user models
1 parent 2c9dece commit 6f5b75c

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

‎spring-security-oauth/src/main/java/org/baeldung/persistence/model/Post.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Date;
44

5+
import javax.persistence.Column;
56
import javax.persistence.Entity;
67
import javax.persistence.GeneratedValue;
78
import javax.persistence.GenerationType;
@@ -16,22 +17,26 @@ public class Post {
1617
@GeneratedValue(strategy = GenerationType.AUTO)
1718
private Long id;
1819

20+
@Column(nullable = false)
1921
private String title;
2022

23+
@Column(nullable = false)
2124
private String subreddit;
2225

26+
@Column(nullable = false)
2327
private String url;
2428

2529
private boolean sendReplies;
2630

31+
@Column(nullable = false)
2732
private Date submissionDate;
2833

2934
private boolean isSent;
3035

3136
private String submissionResponse;
3237

3338
@ManyToOne
34-
@JoinColumn(name = "user_id")
39+
@JoinColumn(name = "user_id", nullable = false)
3540
private User user;
3641

3742
public Post() {

‎spring-security-oauth/src/main/java/org/baeldung/persistence/model/User.java‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.baeldung.persistence.model;
22

33
import java.util.Date;
4-
import java.util.List;
54

5+
import javax.persistence.Column;
66
import javax.persistence.Entity;
77
import javax.persistence.GeneratedValue;
88
import javax.persistence.GenerationType;
99
import javax.persistence.Id;
10-
import javax.persistence.OneToMany;
1110

1211
@Entity
1312
public class User {
@@ -16,6 +15,7 @@ public class User {
1615
@GeneratedValue(strategy = GenerationType.AUTO)
1716
private Long id;
1817

18+
@Column(nullable = false)
1919
private String username;
2020

2121
private String accessToken;
@@ -26,9 +26,6 @@ public class User {
2626

2727
private boolean needCaptcha;
2828

29-
@OneToMany(mappedBy = "user")
30-
private List<Post> posts;
31-
3229
public User() {
3330
super();
3431
}
@@ -81,14 +78,6 @@ public void setNeedCaptcha(boolean needCaptcha) {
8178
this.needCaptcha = needCaptcha;
8279
}
8380

84-
public List<Post> getPosts() {
85-
return posts;
86-
}
87-
88-
public void setPosts(List<Post> posts) {
89-
this.posts = posts;
90-
}
91-
9281
@Override
9382
public int hashCode() {
9483
final int prime = 31;

0 commit comments

Comments
 (0)