Nested one-to-many problem in spring data JPAJava inner class and static nested classHow do I break out of nested loops in Java?Create the perfect JPA entityWhat's the difference between @Component, @Repository & @Service annotations in Spring?What's the difference between JPA and Hibernate?How to ignore unique violation during insert list of objects which contain set of objectWhat is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?Hibernate unable to delete parent/child self-join entityHibernate delete from onetomanyHibernate : Why FetchType.LAZY-annotated collection property eagerly loading?
Does this Foo machine halt?
Is it really ~648.69 km/s delta-v to "land" on the surface of the Sun?
How quickly could a country build a tall concrete wall around a city?
Why isn’t SHA-3 in wider use?
What does "sardine box" mean?
Max Order of an Isogeny Class of Rational Elliptic Curves is 8?
Is this cheap "air conditioner" able to cool a room?
What word can be used to describe a bug in a movie?
English - Acceptable use of parentheses in an author's name
How to mark beverage cans in a cooler for a blind person?
During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?
Can I legally make a real mobile app based on a fictional app from a TV show?
A stranger from Norway wants to have money delivered to me
How do I calculate the difference in lens reach between a superzoom compact and a DSLR zoom lens?
Trying to create a folder with date and time with a space
Performance of a branch and bound algorithm VS branch-cut-heuristics
How can glass marbles naturally occur in a desert?
Write an interpreter for *
How many different ways are there to checkmate in the early game?
Looking for a new job because of relocation - is it okay to tell the real reason?
Improve survivability of bicycle container
Do other countries guarantee freedoms that the United States does not have?
Optimal way to extract "positive part" of a multivariate polynomial
Does the United States guarantee any unique freedoms?
Nested one-to-many problem in spring data JPA
Java inner class and static nested classHow do I break out of nested loops in Java?Create the perfect JPA entityWhat's the difference between @Component, @Repository & @Service annotations in Spring?What's the difference between JPA and Hibernate?How to ignore unique violation during insert list of objects which contain set of objectWhat is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?Hibernate unable to delete parent/child self-join entityHibernate delete from onetomanyHibernate : Why FetchType.LAZY-annotated collection property eagerly loading?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Tables:
survey(id, title);
survey_question(id, survey_id, title);
survey_question_option(id, survey_question_id, content)
Entities:
@Entity
public class Survey implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestion> questions;
@Entity
public class SurveyQuestion implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private Survey survey;
private String title;
@OneToMany(mappedBy = "surveyQuestion", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestionOption> options;
@Entity
public class SurveyQuestionOption implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private SurveyQuestion surveyQuestion;
private String content;
Now add a Survey
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Survey create(@RequestBody Survey survey)
return repository.save(survey);
JSON in request body
"title": "I'm a survey!",
"questions": [
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
,
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
]
Success, then tables like this:
survey:
id title
---------------------------------------
46 I'm a survey!
survey_question:
id survey_id title
---------------------------------------
34 46 I'm a question!
35 46 I'm a question!
survey_question_option:
id survey_question_id content
---------------------------------------
17 34 I'm an option!
18 34 I'm an option!
19 34 I'm an option!
20 34 I'm an option!
21 35 I'm an option!
22 35 I'm an option!
23 35 I'm an option!
24 35 I'm an option!
Now, when I get all surveys by page
@GetMapping
public Page<Survey> findAll(Pageable page)
return repository.findAll(page);
The response is correct, 2 questions, 4 options each question
"content": [
"id": 46,
"title": "I'm a survey!",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
],
"page": 1,
"size": 20,
"totalPages": 1,
"totalCount": 1
BUT, when I get one Survey by id like this:
@GetMapping("/id:\d+") // 46
public Survey get(@PathVariable Long id)
return repository.findById(id).orElse(null);
The response is confusing me, there are a total of 8 questions
"id": 46,
"title": "1111111111111",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
Please tell me how can I solve this problem?
java hibernate jpa spring-data-jpa
add a comment |
Tables:
survey(id, title);
survey_question(id, survey_id, title);
survey_question_option(id, survey_question_id, content)
Entities:
@Entity
public class Survey implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestion> questions;
@Entity
public class SurveyQuestion implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private Survey survey;
private String title;
@OneToMany(mappedBy = "surveyQuestion", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestionOption> options;
@Entity
public class SurveyQuestionOption implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private SurveyQuestion surveyQuestion;
private String content;
Now add a Survey
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Survey create(@RequestBody Survey survey)
return repository.save(survey);
JSON in request body
"title": "I'm a survey!",
"questions": [
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
,
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
]
Success, then tables like this:
survey:
id title
---------------------------------------
46 I'm a survey!
survey_question:
id survey_id title
---------------------------------------
34 46 I'm a question!
35 46 I'm a question!
survey_question_option:
id survey_question_id content
---------------------------------------
17 34 I'm an option!
18 34 I'm an option!
19 34 I'm an option!
20 34 I'm an option!
21 35 I'm an option!
22 35 I'm an option!
23 35 I'm an option!
24 35 I'm an option!
Now, when I get all surveys by page
@GetMapping
public Page<Survey> findAll(Pageable page)
return repository.findAll(page);
The response is correct, 2 questions, 4 options each question
"content": [
"id": 46,
"title": "I'm a survey!",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
],
"page": 1,
"size": 20,
"totalPages": 1,
"totalCount": 1
BUT, when I get one Survey by id like this:
@GetMapping("/id:\d+") // 46
public Survey get(@PathVariable Long id)
return repository.findById(id).orElse(null);
The response is confusing me, there are a total of 8 questions
"id": 46,
"title": "1111111111111",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
Please tell me how can I solve this problem?
java hibernate jpa spring-data-jpa
add a comment |
Tables:
survey(id, title);
survey_question(id, survey_id, title);
survey_question_option(id, survey_question_id, content)
Entities:
@Entity
public class Survey implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestion> questions;
@Entity
public class SurveyQuestion implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private Survey survey;
private String title;
@OneToMany(mappedBy = "surveyQuestion", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestionOption> options;
@Entity
public class SurveyQuestionOption implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private SurveyQuestion surveyQuestion;
private String content;
Now add a Survey
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Survey create(@RequestBody Survey survey)
return repository.save(survey);
JSON in request body
"title": "I'm a survey!",
"questions": [
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
,
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
]
Success, then tables like this:
survey:
id title
---------------------------------------
46 I'm a survey!
survey_question:
id survey_id title
---------------------------------------
34 46 I'm a question!
35 46 I'm a question!
survey_question_option:
id survey_question_id content
---------------------------------------
17 34 I'm an option!
18 34 I'm an option!
19 34 I'm an option!
20 34 I'm an option!
21 35 I'm an option!
22 35 I'm an option!
23 35 I'm an option!
24 35 I'm an option!
Now, when I get all surveys by page
@GetMapping
public Page<Survey> findAll(Pageable page)
return repository.findAll(page);
The response is correct, 2 questions, 4 options each question
"content": [
"id": 46,
"title": "I'm a survey!",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
],
"page": 1,
"size": 20,
"totalPages": 1,
"totalCount": 1
BUT, when I get one Survey by id like this:
@GetMapping("/id:\d+") // 46
public Survey get(@PathVariable Long id)
return repository.findById(id).orElse(null);
The response is confusing me, there are a total of 8 questions
"id": 46,
"title": "1111111111111",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
Please tell me how can I solve this problem?
java hibernate jpa spring-data-jpa
Tables:
survey(id, title);
survey_question(id, survey_id, title);
survey_question_option(id, survey_question_id, content)
Entities:
@Entity
public class Survey implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@OneToMany(mappedBy = "survey", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestion> questions;
@Entity
public class SurveyQuestion implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private Survey survey;
private String title;
@OneToMany(mappedBy = "surveyQuestion", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
private List<SurveyQuestionOption> options;
@Entity
public class SurveyQuestionOption implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(nullable = false)
@ManyToOne
@JsonIgnore
private SurveyQuestion surveyQuestion;
private String content;
Now add a Survey
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Survey create(@RequestBody Survey survey)
return repository.save(survey);
JSON in request body
"title": "I'm a survey!",
"questions": [
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
,
"title": "I'm a question!",
"options": [
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
,
"content": "I'm an option."
]
]
Success, then tables like this:
survey:
id title
---------------------------------------
46 I'm a survey!
survey_question:
id survey_id title
---------------------------------------
34 46 I'm a question!
35 46 I'm a question!
survey_question_option:
id survey_question_id content
---------------------------------------
17 34 I'm an option!
18 34 I'm an option!
19 34 I'm an option!
20 34 I'm an option!
21 35 I'm an option!
22 35 I'm an option!
23 35 I'm an option!
24 35 I'm an option!
Now, when I get all surveys by page
@GetMapping
public Page<Survey> findAll(Pageable page)
return repository.findAll(page);
The response is correct, 2 questions, 4 options each question
"content": [
"id": 46,
"title": "I'm a survey!",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
],
"page": 1,
"size": 20,
"totalPages": 1,
"totalCount": 1
BUT, when I get one Survey by id like this:
@GetMapping("/id:\d+") // 46
public Survey get(@PathVariable Long id)
return repository.findById(id).orElse(null);
The response is confusing me, there are a total of 8 questions
"id": 46,
"title": "1111111111111",
"questions": [
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 34,
"title": "I'm a question!",
"options": [
"id": 17,
"content": "I'm an option."
,
"id": 18,
"content": "I'm an option."
,
"id": 19,
"content": "I'm an option."
,
"id": 20,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
,
"id": 35,
"title": "I'm a question!",
"options": [
"id": 21,
"content": "I'm an option."
,
"id": 22,
"content": "I'm an option."
,
"id": 23,
"content": "I'm an option."
,
"id": 24,
"content": "I'm an option."
]
]
Please tell me how can I solve this problem?
java hibernate jpa spring-data-jpa
java hibernate jpa spring-data-jpa
edited Mar 27 at 8:52
Maciej Kowalski
16.3k8 gold badges27 silver badges43 bronze badges
16.3k8 gold badges27 silver badges43 bronze badges
asked Mar 27 at 7:46
Foy ZhaoFoy Zhao
31 bronze badge
31 bronze badge
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are using fetch = FetchType.EAGER for both
private List<SurveyQuestion> questions;
and
private List<SurveyQuestionOption> options;
So you are fetching the entire tree here always by default.
Now the key here is that you are declaring those dependencies as a List. This means an ordered but allowing duplicates. Here you get a duplicated question per number of its options.
Try to use Set or SortedSet to avoid duplicates.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372110%2fnested-one-to-many-problem-in-spring-data-jpa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are using fetch = FetchType.EAGER for both
private List<SurveyQuestion> questions;
and
private List<SurveyQuestionOption> options;
So you are fetching the entire tree here always by default.
Now the key here is that you are declaring those dependencies as a List. This means an ordered but allowing duplicates. Here you get a duplicated question per number of its options.
Try to use Set or SortedSet to avoid duplicates.
add a comment |
You are using fetch = FetchType.EAGER for both
private List<SurveyQuestion> questions;
and
private List<SurveyQuestionOption> options;
So you are fetching the entire tree here always by default.
Now the key here is that you are declaring those dependencies as a List. This means an ordered but allowing duplicates. Here you get a duplicated question per number of its options.
Try to use Set or SortedSet to avoid duplicates.
add a comment |
You are using fetch = FetchType.EAGER for both
private List<SurveyQuestion> questions;
and
private List<SurveyQuestionOption> options;
So you are fetching the entire tree here always by default.
Now the key here is that you are declaring those dependencies as a List. This means an ordered but allowing duplicates. Here you get a duplicated question per number of its options.
Try to use Set or SortedSet to avoid duplicates.
You are using fetch = FetchType.EAGER for both
private List<SurveyQuestion> questions;
and
private List<SurveyQuestionOption> options;
So you are fetching the entire tree here always by default.
Now the key here is that you are declaring those dependencies as a List. This means an ordered but allowing duplicates. Here you get a duplicated question per number of its options.
Try to use Set or SortedSet to avoid duplicates.
answered Mar 27 at 8:10
Maciej KowalskiMaciej Kowalski
16.3k8 gold badges27 silver badges43 bronze badges
16.3k8 gold badges27 silver badges43 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372110%2fnested-one-to-many-problem-in-spring-data-jpa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown