Why JPA method doesn't wrok with @Entitygrpah

48 Views Asked by At

`@Entity @Table(name = "employees") public class Employee extends Entity {

    @OneToMany(mappedBy = "employee", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    public Set<EmployeeFabric> employeeFabric;

}
@Entity
@Table(name = "employee_fabrics", uniqueConstraints = {@UniqueConstraint(columnNames = {"employee_id",               "fabric_id"})})
    public class EmployeeFabric extends Entity {

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "employee_id", referencedColumnName = "id", columnDefinition = "bigint")
    @NotNull
    public Employee employee;

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "fabric_id", referencedColumnName = "id", columnDefinition = "bigint")
    @NotNull
    public Fabric fabric;

}

@Entity
@Table(name = "fabrics")
public class Fabric extends Entity {

    @OneToMany(mappedBy = "region", fetch = FetchType.LAZY)
    public Set<EmployeeFabric> employeeFabric;

    @OneToMany(mappedBy = "fabric", fetch = FetchType.LAZY)
    public Set<Country> country;

    @Column(nullable = false)
    @NotNull
    @Size(max = 255)
    public String name;

}

@Entity
@Table(name = "countries")
public class Country extends Entity {

    @OneToMany(mappedBy = "country", fetch = FetchType.LAZY)
    public Set<EmployeeCountry> employeeCountry;

    @OneToMany(mappedBy = "area", fetch = FetchType.LAZY)
    public Set<Department> department;

    @ManyToOne
    @JoinColumn(name = "region_id")
    public Fabric fabric;

    @Column(nullable = false)
    @NotNull
    @Size(max = 255)
    public String name;

}

public interface EmployeeFabricRepository extends BaseRepository\<EmployeeFactory, Long\> {

    @EntityGraph(attributePaths = {"fabric", "fabric.country", "fabric.country.department"})
    @Override
    <S extends EmployeeFactory> S save(S entity);

}`

I'm trying to get "EmployeeFabric" with departments I can't use Eager. The entity graph doesn't work here; I get an employeeFactory without departments. With custom methods, it works, but I need to use the default save. Does anyone know the reason?

0

There are 0 best solutions below