0
我有以下实体:渴望与NamedEntityGraph获取返回过多行
@Entity
@NamedEntityGraph(name = "Text.WithRows", attributeNodes = { @NamedAttributeNode("rows") })
public class Text {
@Id
@Column(name = "uuid", nullable = false, unique = true)
UUID uuid;
@Column(name = "belongsTo")
UUID belongsTo;
@OneToMany
@JoinColumn(name = "text_id")
List<TextRow> rows;
}
@Entity
public class TextRow {
@Id
@Column(name = "uuid", nullable = false, unique = true)
private UUID uuid;
@Column(name = "content", nullable = false, length = 255)
private String content;
}
我也有一个Spring数据JPA库定义是这样的:
public interface TextRepository extends PagingAndSortingRepository<Text, UUID>, JpaSpecificationExecutor<Text> {
@EntityGraph(value = "Text.WithRows", type = EntityGraphType.LOAD)
List<Text> findAllByBelongsTo(UUID belongsTo)
}
我想有TextRows热切加载,当我从存储库执行find-Method。因此,我在上面的代码中引入了NamedEntityGraph-和EntityGraph-annotations。
我在我的数据库的文本表中有2个条目,每个条目在TextRow表中有3个条目。
我期望findAllByBelongsTo方法返回一个带有两个Text-instances的列表。相反,它返回一个包含6个文本实例的列表。
我不明白为什么会发生这种情况。有人可以给我一些指导或解决方案吗?
谢谢!