Questions tagged [entitygraph]

In JPA Entity Graphs give the ability to specify fetch plans.

In JPA Entity Graphs give the ability to specify fetch plans.

This is useful since it allows you to customise the data that is retrieved with a query or find operation. When working with mid to large size applications is common to display data from the same entity in different and many ways. In other cases, you just want to select a smallest set of information to optimize the performance of your application.

98 questions
59
votes
6 answers

Spring Data JPA And NamedEntityGraphs

currently I am wrestling with being able to fetch only the data I need. The findAll() method needs to fetch data dependant on where its getting called. I do not want to end up writing different methods for each entity graph. Also, I would avoid…
dendimiiii
  • 1,659
  • 3
  • 15
  • 26
45
votes
1 answer

What is the difference between FETCH and LOAD for Entity graph of JPA?

I'm new to JPA and I'm trying to use entity graph. And I realized when I retrieve data, I need to specify which EntityGraphType I want to use. I read JPA2.1 specification but I'm still not sure how can I use these 2 options properly... the question…
Naga
  • 10,944
  • 2
  • 21
  • 38
20
votes
4 answers

JPA inheritance @EntityGraph include optional associations of subclasses

Given the following domain model, I want to load all Answers including their Values and their respective sub-children and put it in an AnswerDTO to then convert to JSON. I have a working solution but it suffers from the N+1 problem that I want to…
Stuck
  • 11,225
  • 11
  • 59
  • 104
9
votes
1 answer

Spring data JPA - using @EntityGraph causes "Entity graph specified is not applicable to the entity" warning

I upgraded my app from spring boot 2.2.5 to 2.3.3 and I'm using spring data JPA starter with 5.4.20.Final onboard. My entites are enhanced at compile time. Now when I'm using @EntityGraph annotation with attributePaths property over overriden…
Michał Stochmal
  • 5,895
  • 4
  • 36
  • 44
9
votes
1 answer

Hibernate ignores fetchgraph

This is my entity: public class PersonItem implements Serializable{ @Id @Column(name="col1") private String guid; @Column(name="col2") private String name; @Column(name="col3") private String surname; …
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
8
votes
1 answer

Spring Data JPA findAll with different EntityGraph

in Spring Data JPA Repository i need to specify multiple methods that do the same thing (eg. findAll) but specifying different @EntityGraph annotation (the goal is to have optimized methods to use in different services). Es. @Repository public…
Gabriele Muscas
  • 1,325
  • 1
  • 9
  • 16
7
votes
1 answer

Can subgraph reference another named entity graph?

So I have found a few answers where one says it is possible to do so and the other says it is not. This kind of confused me because when I tried to do so - I failed. What I want is to reference a named entity graph in a subgraph like…
THE Waterfall
  • 645
  • 6
  • 17
7
votes
0 answers

EntityGraph - You must define a fetch group manager at descriptor in order to set a fetch group on the query

I would like use Entity Graphs in EclipseLink and GlassFish. @Entity @NamedQueries({ @NamedQuery(name = "invoice.all", query = "SELECT i FROM Invoice i")}) @NamedEntityGraph(name = "graph.invoice", …
B. J.
  • 89
  • 1
  • 6
6
votes
0 answers

Using Entity Graph with DTO Projection using ResultTransformer returns null value

Hello I am new in jpa + criteria API + hibernate.. I have doubt related to use of ResultTransformer in jpa criteria API. I am having two entity Department and Employee. one to many mapping between department and employee. i want to use entitygraph…
6
votes
1 answer

JPA EntityGraph, create subgraph of PluralAttribute programmably by using static MetaModel

When I have below entity. @Entity class Article { @OneToMany Set comments; } @Entity class Comment { @ManyToOne User author; } And create some view specification class using EntityGraph and static metamodel like below. class…
Yuki Yoshida
  • 1,233
  • 1
  • 15
  • 28
6
votes
1 answer

How to fetch a whole entity graph using JPA

I am using JPA 2.0 with OpenJPA as underlying implementation. I have an entity which maps to itself to represent parent-child hierarchy between entities. An entity can have more than one children but a single parent at most. Entity with no parent is…
Mandroid
  • 6,200
  • 12
  • 64
  • 134
6
votes
2 answers

What's the goal of the JPA Entity Graph?

I’ve been learning about JPA and I found that we can use entity graph since JPA 2.1. But I've not understood the merit of the entity graph yet. I know that one of the merits to use an entity graph is we can specify only the data which we want to get…
Naga
  • 10,944
  • 2
  • 21
  • 38
5
votes
1 answer

Spring Data JPA runs additional select queries when using entity graph and mapped object is not present (null)

I have 2 entities in a one to one relationship (it can be many to one but for this case I don't think it matters much) like such: @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; …
Allen Perry
  • 191
  • 1
  • 8
5
votes
1 answer

Spring Data JPA, parametrize @EntityGraph in CrudRepository interface

Is it possible with Spring Data JPA to do smth. like this: public interface UserDao extends CrudRepository { @EntityGraph(value = :graphName, type = EntityGraph.EntityGraphType.LOAD) @Query(value = "SELECT DISTINCT u FROM User u") …
Andreas Gelever
  • 1,736
  • 3
  • 19
  • 25
5
votes
2 answers

How to limit columns used in a Hibernate entity graph

Hibernate 5.0.10 I have a subgraph defined that looks like this: @NamedSubgraph(name = "proc", attributeNodes = { @NamedAttributeNode("name"), @NamedAttributeNode("childTable1"), @NamedAttributeNode("childTable2"), …
John Ament
  • 11,595
  • 1
  • 36
  • 45
1
2 3 4 5 6 7