注释春数据仓库JPA的方法findAll()有@EntityGraph:
import org.springframework.data.jpa.repository.JpaRepository;
[...]
public interface OptgrpRepository extends JpaRepository<Optgrp> {
@EntityGraph(value = "Optgrp.sysoptions")
List<Optgrp> findAll();
Run Code Online (Sandbox Code Playgroud)
}
导致此错误消息:
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!
问题:是否可以在@EntityGraph查找所有实体的Spring Data JPA存储库方法上使用注释?
编辑:正如评论中所要求的,这是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<>();
}
Run Code Online (Sandbox Code Playgroud)
而Sysoption实体类也是:
@Entity
public class Sysoption implements Serializable {
[...]
@ManyToOne
@JoinColumn(name = "optgrp_id", insertable=false, updatable=false)
private Optgrp optgrp;
}
Run Code Online (Sandbox Code Playgroud)
对于所有也使用 Stack Overflow 作为知识数据库的人,我记录了 Markus Pscheidts 挑战的新状态。三年零六个月后,@EntityGraph注解现在直接findAll()作用于 Spring Data中的函数JpaRepository,正如 Markus 最初预期的那样。
@Repository
public interface ImportMovieDAO extends JpaRepository<ImportMovie, Long> {
@NotNull
@Override
@EntityGraph(value = "graph.ImportMovie.videoPaths")
List<ImportMovie> findAll();
}
Run Code Online (Sandbox Code Playgroud)
测试中使用的版本:包含 spring-boot-starter-data-jpa 的 Spring Boot 2.0.3.RELEASE。
使用名称findByIdNotNull是结合 findAll() 和实体图的一种方式:
@EntityGraph(value = "Optgrp.sysoptions")
List<Optgrp> findByIdNotNull();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |