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
5
votes
2 answers

How to load only specified attributes in subgraph in an @NamedEntityGraph

I want to load an UserReference object from the database, but from the verifier attribute I want to load only the id, firstName and lastName, so that the userReference would look something like this: { "id": 1, "company": "company1", …
dd1714
  • 139
  • 1
  • 6
4
votes
1 answer

entitygraph not working - returning all the entity

I'm trying the EntityGraph in a simple scenario of springdata jpa: The idea is just to get an entity with its id field and omit another field called name. This is the entity to be retrieved: Entity @NamedEntityGraph(name = "Region.id", …
ronenwo
  • 107
  • 6
4
votes
1 answer

@NamedEntityGraphs on findAll()

I use @NamedEntityGraph in my application @NamedEntityGraphs({ @NamedEntityGraph(name = "graph.Employee.assignments", attributeNodes = @NamedAttributeNode("assignmentProjectEmployeeSet")), @NamedEntityGraph(name = "graph.Employee.absences",…
user8914226
4
votes
2 answers

JPA entity graph: which join types?

JPA entity graph: e.g. Order - OrderItem - Product @NamedEntityGraph(name = "order", attributeNodes = @NamedAttributeNode(value = "orderItems", subgraph = "orderItems"), subgraphs = @NamedSubgraph(name = "orderItems", attributeNodes =…
eastwater
  • 4,624
  • 9
  • 49
  • 118
4
votes
1 answer

JPA EntityGraph based on meta model containing MappedSuperclass not possible?

I'm trying to use the type safe method EntityGraph.addAttributeNodes(Attribute ... attribute) for constructing my entity graph. I have a type hierarchy with a @MappedSuperclass that basically looks like this: @MappedSuperclass public abstract…
Hein Blöd
  • 1,553
  • 1
  • 18
  • 25
4
votes
3 answers

How to use the IN clause in an JPA @Query annotation

I have defined this method @Query("select cs from CenterStudy cs where cs.id in (?1)") @EntityGraph(value = "centerStudyAndNotifiedUsers", type = EntityGraph.EntityGraphType.LOAD) List findAllByIdsWithCenterAndUsers(List
RaresI
  • 461
  • 1
  • 6
  • 19
3
votes
0 answers

Nested embedded objects in Hibernate 6

I have problem with nested embedded objects in Hibernate 6.1.4.Final (Java 17, Spring-Data 3.0.0-M5) which I stripped down to the following lines of code @Entity public class Foo{ @Id @GeneratedValue(strategy = GenerationType.AUTO) …
GroppP2010
  • 31
  • 1
3
votes
1 answer

Why hibernate entity graph fetch nested lazy collections

I am trying to use entity graph for triggering lazy collections to load but unfortunately entity graph also triggers all nested collections. I am using spring-data-jpa-entity-graph library for creating entity graphs at runtime. @Entity public class…
user3714967
  • 1,575
  • 3
  • 14
  • 29
3
votes
2 answers

Spring JPA Entity Graph and Self Reference occur N+1 query

I tried to use entity graph to avoid N+1 query, and it work as expected. It is different in self reference entity, though these code could get correct list, the N+1 query occurred. My question is how to eliminate N+1 query with self reference…
sadolin
  • 31
  • 2
3
votes
1 answer

MultipleBagFetchException whent I try load entity with 2 collections use JPA EntityGraph

I have user entity: @ToString @Data @Entity @Table(name = "users") @NamedEntityGraph(name = "UserWithItems", attributeNodes = { @NamedAttributeNode("items"), @NamedAttributeNode("roles") }) public…
ip696
  • 6,574
  • 12
  • 65
  • 128
3
votes
2 answers

Named Entity Graphs Naming Scope in Spring Data

I've recently discovered Named Entity Graphs, and I'm trying to implement them in a clean, DRY way. What I'm not sure about (and reading through the JPA and Spring Data Docs hasn't answered) is the scope of the names used. Are the private to the…
Jordan Mackie
  • 2,264
  • 4
  • 25
  • 45
3
votes
0 answers

Spring JpaRepository using EntityGraph returns null instead of Optional

Calling this method: @EntityGraph(attributePaths = "permissionGroups") Optional findOneWithPermissionGroupsByLogin(String login); With non-exsisting user login returns null instead of Optional.of(null). I would like to figure out what…
3
votes
0 answers

Spring data pagination with entity graph

I need to use pagination in conjuntion with a custom query using an Entity Graph. My repository looks like this: @Repository public interface MaintenanceRepository extends JpaRepository, QueryDslPredicateExecutor { …
rvillablanca
  • 1,606
  • 3
  • 21
  • 34
3
votes
0 answers

EclipseLink JPA: fetch group cannot be set on report query

EclipseLink: fetch group cannot be set on report query. TypedQuery query = em.createQuery(criteriaQuery); query.setHint("javax.persistence.fetchgraph", entityGraph); List results = query.getResultList(); What is report…
Dave
  • 759
  • 2
  • 9
  • 31
3
votes
0 answers

@NamedEntityGraph is not working when using with Spring data jpa 1.9.1

I define the following entity @Entity @NamedEntityGraph(name="Course.findByCourseStatusGraph", attributeNodes={ @NamedAttributeNode("id"), @NamedAttributeNode("courseGUID"), @NamedAttributeNode(value="courseTitle"), …
Basit
  • 8,426
  • 46
  • 116
  • 196