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個文本實例的列表。
我不明白爲什麼會發生這種情況。有人可以給我一些指導或解決方案嗎?
謝謝!