Home Spring Data throwing an EntityNotFoundException only with EntityGraph
Reply: 0

Spring Data throwing an EntityNotFoundException only with EntityGraph

user3738 Published in May 21, 2018, 11:02 am

I'm currently working on a bug that I can't explain, so I'm looking for some help here.

I'm using Spring Data to get my objects, and they are all managed by a column called "FlagCMS" which, if set to 'S' means that the object should not be linked to any other new one. It's a kind of soft-deleting that worked fine until now.

The classes are defined like this (minus a lot of unrelated code) :


@Table(name = "action")
    @NamedEntityGraph(name = "Action.maj", attributeNodes = {
public class Action {

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "action", cascade = CascadeType.ALL)
    private Set<OuvrageAction> ouvragesAction = new HashSet<>();

    protected void cascadeDelete() {
        if (isDeleted()) {

    public Collection<OuvrageAction> getOuvragesAction() {
        return ouvragesAction;

    public void setOuvragesAction(final Set<OuvrageAction> ouvragesAction) {
        this.ouvragesAction = ouvragesAction;

    public List<Ouvrage> getOuvrages() {
        return ouvragesAction.stream().map(OuvrageAction::get).collect(Collectors.toList());


@Table(name = "ouvrage_action")
    @AttributeOverride(name = "id", column = @Column(name = "id_action_ouvrage"))
public class OuvrageAction extends AbstractReferentielAction<Ouvrage> {

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "id_ouvrage", nullable = false)
    private Ouvrage ouvrage;

    public OuvrageAction() {

    public OuvrageAction(Ouvrage ouvrage, Action action) {
        this.ouvrage = ouvrage;

    public Ouvrage getOuvrage() {
        return ouvrage;

    public void setOuvrage(Ouvrage ouvrage) {
        this.ouvrage = ouvrage;



@Table(name = "ouvrage")
public class Ouvrage {

    @Column(name = "code")
    protected String code;

    public String getCode() {
        return code;

    public void setCode(String code) {
        this.code = code;

WHERE_NOSOFTDELETED is defined like this in FlagCMS.java :

public static final String WHERE_NOSOFTDELETED = "(flag_cms = 'C' or flag_cms = 'M')";

And I access the Action object using two different JpaRepositories defining similar methods, one keeping the lazy loading, and one using the EntityGraph :

@EntityGraph(value = "Action.maj", type = EntityGraphType.LOAD)
List<Action> findDistinctByCodeIn(List<String> codes);


List<Action> findDistinctByCodeIn(List<String> codes);

Now let's say I have an Action object linked to a Ouvrage object. The second have FlagCMS set to S. Using the lazy repository, everything is fine, I get my Actions and can access the code property of Ouvrage through it. Accessing the Action by using the repository with EntityGraph, I only get an EntityNotFoundException telling me that the Ouvrage object does not exist.

This does not seem consistent to me.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338169 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO