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 53bff68

Browse files
author
Rajeev Kumar Singh
committed
Added optional=false to @manytoone
1 parent 41bf4e7 commit 53bff68

File tree

1 file changed

+6
-3
lines changed
  • jpa-one-to-many-demo/src/main/java/com/example/jpa/model

1 file changed

+6
-3
lines changed

‎jpa-one-to-many-demo/src/main/java/com/example/jpa/model/Comment.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.example.jpa.model;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
3+
import com.fasterxml.jackson.annotation.*;
44

55
import javax.persistence.*;
66
import javax.validation.constraints.NotNull;
7+
78
import org.hibernate.annotations.OnDelete;
89
import org.hibernate.annotations.OnDeleteAction;
910

@@ -21,10 +22,12 @@ public class Comment extends AuditModel {
2122
@Lob
2223
private String text;
2324

24-
@ManyToOne(fetch = FetchType.LAZY)
25+
@ManyToOne(fetch = FetchType.LAZY, optional = false)
2526
@JoinColumn(name = "post_id", nullable = false)
2627
@OnDelete(action = OnDeleteAction.CASCADE)
27-
@JsonIgnore
28+
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
29+
@JsonIdentityReference(alwaysAsId=true)
30+
@JsonProperty("post_id")
2831
private Post post;
2932

3033
public Long getId() {

0 commit comments

Comments
(0)

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