I have an entity graph defined in my Person entity. When I declare the phone attribute as an attribute node, a join clause is created and only one select is executed, as expected. But when I remove the phone attribute from the entity graph, the phone field is still loaded, but now with a new select query for each Person retrivied. Is it possible to ignore an attribute in a particular EntityGraph?
Person Entity:
@Entity
@Table(name = "person")
@NamedEntityGraph(
name = Person.PERSON_LAZY,
attributeNodes = {}
)
public class Person {
public static final String Person_LAZY = "person.lazy";
@Id
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@JoinColumn(name = "phone")
@ManyToOne
private Phone phone;
}
PersonRepository:
@Repository
public interface PersonRepository extends JpaRepository<Person, Long> {
@EntityGraph(value = Person.PERSON_LAZY, type = EntityGraphType.FETCH)
@Query("SELECT p FROM Person p")
public List<Person> findAllLazy();
}