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

Hibernate entity graph not fetching all referenced entities

I have two entities with ManyToMany-Relation connected via join table: @Entity @Table(name = "stations") public class StationEntity implements Identifyable { @Id @Column(name = "station_id") private Long id; @ManyToMany …
Seb
  • 1,721
  • 1
  • 17
  • 30
2
votes
0 answers

JPA entity graph issue

i have many to many relationship between book and author, i have 3 tables: author, book and author_book. @Entity() @Table(name = "author") @NamedEntityGraph(name = "Book.detail", attributeNodes =…
jake101
  • 21
  • 2
2
votes
0 answers

Avoiding "HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!" using Spring Data

I'm using Spring Data and faced up the issue HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! warning message. The entity relationship that cause that issue is pretty simple, I use @NamedEntityGraph in order to…
Ruslan
  • 6,090
  • 1
  • 21
  • 36
2
votes
0 answers

Using JPA Entity Graph in DAO

I have defined the JPA Entity Graph on my Entity class, and it looks like follows. UserTable.java @Entity @Table(name = "USER") @NamedEntityGraph( name = "user-entity-graph-with-photos", attributeNodes = { …
wesleyy
  • 2,575
  • 9
  • 34
  • 54
2
votes
1 answer

Hibernate EntityGraph on @Basic fields does not work as expected

It seems that Hibernate ignores any @Basic field specified in javax.persistence.fetchgraph and always loads the whole object until we explicitly define the field as @Basic(fecth=LAZY). However the JPA 2.1 standard says: To specify a fetch graph,…
2
votes
1 answer

Eager fetching with multiple selects but without FetchType.EAGER annotation

I want to eagerly fetch one-to-many List-s in some use cases (but not always, so @OneToMany(fetch=FetchType.EAGER) won't be good), and I also want JPA to use separate SQL selects to fetch those List-s (one select per List, not one per List item),…
ddekany
  • 29,656
  • 4
  • 57
  • 64
1
vote
1 answer

Spring Data Hibernate: How to use fetch type specified in entity for custom queries?

I'm working on a Spring Boot 3.x application with Spring Data and Hibernate 6.x. I've got an entity class that looks like this: @Entity public class User { @Id private UUID id = UUID.randomUUID(); @Column private String country; …
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
1
vote
1 answer

Why JPA Inheritance with EntityGraph queries twice a related entity?

I have mapped through JPA the following entities: @Entity(name = "Parent") @Table(name = "parent") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type") public abstract class Parent { @Id @GenericGenerator(name…
João Pedro Schmitt
  • 1,046
  • 1
  • 11
  • 25
1
vote
1 answer

No property found for type after adding EntityGraphJpaSpecificationExecutor to repository

I have an entity with a relation to another one: public class MyEntity { @Id @GeneratedValue @Column(name = "id", nullable = false) private UUID id; @Column(name = "deleted", nullable = false) private Boolean deleted =…
Nora Na
  • 162
  • 1
  • 16
1
vote
0 answers

How to cope with "could not load collection by subselect: " in optimal way

Technology: Spring Data, QueryDSL There is an entity with entity graph and three collections which not included in entity graph @NamedEntityGraphs({ @NamedEntityGraph( name = "companySale-fetch-all", attributeNodes = { …
Oleg
  • 11
  • 1
1
vote
1 answer

JPA EntityGraph making a Cartesian Product with subgraph

I am working with Spring Data JPA and Entity Graphs. I have the following Entity structure: Result entity has a list of SingleQuestionResponse entities, and the SingleQuestionResponse entity has a set of Answer entities (markedAnswers). public class…
furry12
  • 902
  • 1
  • 14
  • 31
1
vote
1 answer

Lazily fetching entity with multiple relations: Could not write JSON: failed to lazily initialize a collection of role

Message Could not write JSON: failed to lazily initialize a collection of role: core.domain.Cat.catFoods, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize…
1
vote
2 answers

How to avoid "code smell" when using @NamedEntityGraphs annotation?

In IntellyJ Idea I have installed SonarLint. Code analizer says that I have to remove the "NamedEntityGraphs" wrapper from this annotation group. Here is my code: @NamedEntityGraphs({ @NamedEntityGraph( name =…
Vladimir Jotov
  • 188
  • 1
  • 8
1
vote
1 answer

Spring Data JPA + Bytecode Enhancement

Is it possible to load @*ToOne attributes eagerly using JPA interface(Entity Graphs) which are set lazy using @LazyToOne , @LazyGroup in the parent entity class and enabled bytecode enhancement ? I am trying to load such attributes eagerly using…
1
vote
1 answer

EntityGraph not fetching relations provided dynamically

I am trying to load lazy attributes of the entity using spring JPA repository and Entity graph , EntityGraph is not fetching relations provided dynamically , instead it fetches attributes as per the static fetch type defined in entity for that…