File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
jpa-one-to-many-demo/src/main/java/com/example/jpa/model Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .example .jpa .model ;
2
2
3
- import com .fasterxml .jackson .annotation .JsonIgnore ;
3
+ import com .fasterxml .jackson .annotation .* ;
4
4
5
5
import javax .persistence .*;
6
6
import javax .validation .constraints .NotNull ;
7
+
7
8
import org .hibernate .annotations .OnDelete ;
8
9
import org .hibernate .annotations .OnDeleteAction ;
9
10
@@ -21,10 +22,12 @@ public class Comment extends AuditModel {
21
22
@ Lob
22
23
private String text ;
23
24
24
- @ ManyToOne (fetch = FetchType .LAZY )
25
+ @ ManyToOne (fetch = FetchType .LAZY , optional = false )
25
26
@ JoinColumn (name = "post_id" , nullable = false )
26
27
@ OnDelete (action = OnDeleteAction .CASCADE )
27
- @ JsonIgnore
28
+ @ JsonIdentityInfo (generator =ObjectIdGenerators .PropertyGenerator .class , property ="id" )
29
+ @ JsonIdentityReference (alwaysAsId =true )
30
+ @ JsonProperty ("post_id" )
28
31
private Post post ;
29
32
30
33
public Long getId () {
You can’t perform that action at this time.
0 commit comments