【发布时间】:2020-09-13 02:11:28
【问题描述】:
我的代码:
@MappedSuperclass
public abstract class Header {
public abstract List<Line> getLines();
}
@Entity
public class ChildHeader extends Header{
@OneToMany
public List<ChildLine> getLines();
}
@MappedSuperclass
public abstract class Line {
public abstract Header getHeader();
}
@Entity
public class ChildLine extends Line {
@ManyToOne
public ChildHeader getHeader();
}
问题:我收到错误消息“错误:'ChildHeader'中的'getLines()'与'Header'中的'getLines()'发生冲突;尝试使用不兼容的返回类型”
尝试的解决方案:将List<Line> 更改为<T extends Line> List<T> 并将List<ChildLine> 更改为<T extends ChildLine> List<T>
新错误:“ChildHeader”中的“getLines()”与“Header”中的“getLines()”发生冲突;两种方法都有相同的擦除,但都没有覆盖另一个
尝试的解决方案:尝试使用 Line[] 和 ChildLine[] 而不是列表
新错误:“列表/数组必须用@OrderColumn(或@IndexColumn)注释”,但没有排序列。数组的顺序无关紧要,但似乎 @OneToMany 或 JPA 需要一个。
这是不可能的情况。我能做什么?
【问题讨论】:
标签: java jpa generics inheritance