使用@EntityGraph
注释Spring Data JPA存储库方法findAll()
:
import org.springframework.data.jpa.repository.JpaRepository;
[...]
public interface OptgrpRepository extends JpaRepository<Optgrp> {
@EntityGraph(value = "Optgrp.sysoptions")
List<Optgrp> findAll();
}
导致以下错误消息:
org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Optgrp!
当将findAll()
更改为其他名称时,会发生相同的错误:
findAllWithDetail()
--> No property findAllWithDetail found for type Optgrp!
findWithDetailAll()
--> No property findWithDetailAll found for type Optgrp!
问题:是否有可能在查找所有实体的Spring Data JPA存储库方法上使用@EntityGraph
注释?
编辑:如评论中所询问的,这是来自Optgrp
实体类的摘录:
@Entity
@NamedEntityGraph(name = "Optgrp.sysoptions", attributeNodes = @NamedAttributeNode("sysoptions"))
public class Optgrp implements Serializable {
[...]
@OneToMany(mappedBy="optgrp", cascade = CascadeType.ALL, orphanRemoval=true)
@OrderBy(clause = "ordnr ASC")
private List<Sysoption> sysoptions = new ArrayList<>();
}
同时也需要翻译Sysoption
实体类:
@Entity
public class Sysoption implements Serializable {
[...]
@ManyToOne
@JoinColumn(name = "optgrp_id", insertable=false, updatable=false)
private Optgrp optgrp;
}
@NamedEntityGraph(name = "Optgrp.sysoptions", attributeNodes = @NamedAttributeNode("sysoptions"))
? - Nitin AroraNamedEntityGraph
被定义在Optgrp
领域实体类中。我已经编辑了问题。 - Markus Pscheidt