Reputation: 168
I have a Two Table : opinionPoll
and result
.
Having One(opinionPoll) to Many(result) relation
.
When I try to get record from other table using an Alias then got a error for mapping. when I delete the parent child(results) are not deleted but parent deleted. I think my problem is in mapping so the below code of my tables.
For opinionPoll:
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
@JoinColumn(name = "pid", nullable = false, updatable = true)
private List<PollResult> pollResults = new ArrayList<PollResult>() ;
For result:
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "pid", insertable = false, updatable = false)
private OpinionPoll opinionPoll;
Upvotes: 1
Views: 81
Reputation: 152
Try this :
For OpinionPoll:
// mappedBy "opinionPoll" --> the OpinionPoll object in Result class
@OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL,mappedBy="opinionPoll")
private List<PollResult> pollResults = new ArrayList<PollResult>() ;
For Result :
@ManyToOne
@JoinColumn(name = "pid")
private OpinionPoll opinionPoll;
Upvotes: 2