I have two entities. I want a bidirectional relationship between projects and tasks.
- A project has one or more tasks
- A task is associated to only one project
There are my entities:
ProjectEntity.java
Код: Выделить всё
@Entity @Table(name = "projects") public class ProjectEntity { @Id @GeneratedValue @Column(name = "pr_id") private long id; @Column(name = "pr_name", nullable = false) private String name; @OneToMany(cascade=CascadeType.ALL, mappedBy="project",orphanRemoval=true) @JsonBackReference private Set tasks = new HashSet(); // Getters, constructors, setters
Код: Выделить всё
@Entity @Table(name = "tasks") public class TaskEntity { @Id @GeneratedValue @Column(name = "ta_id") private long id; @Column(name = "ta_name") private String name; @ManyToOne @JoinColumn(name="pr_id") @JsonManagedReference private ProjectEntity project; // Getters, constructors, setters
Код: Выделить всё
ProjectEntity
Код: Выделить всё
TaskEntity
Here, I'm using
Код: Выделить всё
@JsonManagedReference
Код: Выделить всё
@JsonBackReference
Код: Выделить всё
ProjectEntity
Код: Выделить всё
@JsonBackReference
Could you help me to get back tasks list in
Код: Выделить всё
ProjectEntity
Код: Выделить всё
@JsonIdentifyInfo
Hope I'm understandable

Источник: https://stackoverflow.com/questions/311 ... lationship