Annotating the Spring Data JPA repository method findAll()
with @EntityGraph
:
import org.springframework.data.jpa.repository.JpaRepository;
[...]
public interface OptgrpRepository extends JpaRepository<Optgrp> {
@EntityGraph(value = "Optgrp.sysoptions")
List<Optgrp> findAll();
}
leads to this error message:
org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Optgrp!
Same error happens when changing findAll()
to other names:
findAllWithDetail()
--> No property findAllWithDetail found for type Optgrp!
findWithDetailAll()
--> No property findWithDetailAll found for type Optgrp!
Question: Is it at all possible to use the @EntityGraph
annotation on a Spring Data JPA repository method that finds all entities?
EDIT: as asked in the comment, here's the extract from the Optgrp
entity class:
@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<>();
}
And the Sysoption
entity class as well:
@Entity
public class Sysoption implements Serializable {
[...]
@ManyToOne
@JoinColumn(name = "optgrp_id", insertable=false, updatable=false)
private Optgrp optgrp;
}
For all, who are using Stack Overflow as knowledge database too, I record a new status to Markus Pscheidts challenge. Three years and six months later the @EntityGraph
annotation works now directly at the findAll()
function in Spring Data JpaRepository
, as Markus original expected.
@Repository
public interface ImportMovieDAO extends JpaRepository<ImportMovie, Long> {
@NotNull
@Override
@EntityGraph(value = "graph.ImportMovie.videoPaths")
List<ImportMovie> findAll();
}
Versions used in the test: Spring Boot 2.0.3.RELEASE with included spring-boot-starter-data-jpa.
Using the name findByIdNotNull
is one way to combine both findAll() and entity graph:
@EntityGraph(value = "Optgrp.sysoptions")
List<Optgrp> findByIdNotNull();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With