Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple/Default EntityGraphs #51

Closed
JamesPeters98 opened this issue Feb 1, 2021 · 3 comments
Closed

Multiple/Default EntityGraphs #51

JamesPeters98 opened this issue Feb 1, 2021 · 3 comments

Comments

@JamesPeters98
Copy link

Hey! Is it currently possible to set the default entity graph and then have any DynamicEntityGraph's just add attributes on top of the default.

I have a scenario where I'd like certain fields in an Entity to always be Fetched and then be able to choose what other fields using the EntityGraph supplied!

@reda-alaoui
Copy link
Member

Hey,

If you use Hibernate, since https://hibernate.atlassian.net/browse/HHH-8776, the concept of "default" EntityGraph defined by this extension is not needed anymore.
You can just rely on your Entity annotations fetch type and apply an EntityGraph of type LOAD javax.persistence.loadgraph.

Here is an example:

@Entity
class A {
  @OneToOne(fetchType = EAGER)
  private B b;

  @OneToOne(fetchType = LAZY)
  private C c;
}
// This will load b + c
aRepository.findById(1, new DynamicEntityGraph(LOAD, Collections.singletonList("c")));

@reda-alaoui
Copy link
Member

From https://docs.oracle.com/javaee/7/tutorial/persistence-entitygraphs001.htm :

To specify a load graph, set the javax.persistence.loadgraph property when you execute an EntityManager.find or query operation. A load graph consists of the fields explicitly specified in the EntityGraph instance plus any fields in the default entity graph.

@JamesPeters98
Copy link
Author

I had tried that but it doesn't work with Spring Boot and Spring Data which appears to just ignore FetchType Completely, that's why I'm using Entity Graphs in the first place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants