0
@Entity
@Table(name = "EMPLOYEE")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Employee extends AuditModel implements Serializable {

@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employee_generator")
    @SequenceGenerator(name = "employee_generator", sequenceName = "employee_seq", allocationSize = 50)
    @Column(name = "EMPLOYEE_ID")
    long employeeId;

    @Column(name = "FIRST_NAME")
    String firstName;

    @Column(name = "LAST_NAME")
    String lastName;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "employee", cascade = CascadeType.ALL)
    List<Task> tasks;

}


@Entity
@Table(name = "TASK")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Task implements Serializable {

    private static final long serialVersionUID = 1L;

    public Task() {
        super();
    }

    public Task(String description) {
        this.description = description;
    }

    // details
    // type, priority, label, status

    // description

    // customer address
    // state, city, state

    // people
    // assignee, reporter

    // dates
    // created, updated

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "task_generator")
    @SequenceGenerator(name="task_generator", sequenceName = "task_seq", allocationSize=50)
    @Column(name = "TASK_ID")
    long taskId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EMPLOYEE_ID")
    @JsonIgnore
    Employee employee;

}

when I get from employee -> task. I am getting an employee object and list of tasks.w ex:

{

"employeeId":1,

"tasks":[
{
"taskId":1,
"title":"first task"
}

]
}

}

Now the problem I want to get from Task(child) -> employee(parent). I am not getting employee object because I put @JsonIgnore annotation. If I remove the @JsonIgnore I get an infinite loop. Now I want to take employee object from task object, how can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kumaresan Perumal
  • 1,926
  • 2
  • 29
  • 35

0 Answers0