You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@MappedSuperclass
class abstract Base {
@Id
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
@Entity
class A extends Base {
@OneToMany
private List<B> bs;
public List<B> getBs() {
return bs;
}
public void setBs(List<B> bs) {
this.bs = bs;
}
}
@Entity
class B extends Base {
@ManyToOne
@JoinColumn(name="a_id")
private A a;
public Integer getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
}
A and B have a bidirectional relationship and when they are both loaded and then it creates an infinite recursion and a stackoverflowerror. I started looking at the code and saw that it was using reflection but it occurred to me that making the superclass Id property protected instead of private might work like so.
@MappedSuperclass
class abstract Base {
@Id
protected Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
And it worked! I just wanted to share this in case anyone else had the same issue, i'm not sure if its worth a fix because using protected on the superclass seems fine to me but it did take me ages to work out what was wrong so maybe it is worth a fix. If you think it is worth fixing I can have a go at a PR.
Cheers,
Cadell
The text was updated successfully, but these errors were encountered:
A and B have a bidirectional relationship and when they are both loaded and then it creates an infinite recursion and a stackoverflowerror. I started looking at the code and saw that it was using reflection but it occurred to me that making the superclass Id property protected instead of private might work like so.
And it worked! I just wanted to share this in case anyone else had the same issue, i'm not sure if its worth a fix because using protected on the superclass seems fine to me but it did take me ages to work out what was wrong so maybe it is worth a fix. If you think it is worth fixing I can have a go at a PR.
Cheers,
Cadell
The text was updated successfully, but these errors were encountered: