jakartaee / jakartaee/persistence

static constructor methods for entity graph nodes

Open
#834 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
268
Forks
78
Avg merge
1d 6h
Merged PRs (30d)
13

Description

One of these days (almost certainly not for JPA 4.0!) we should look at adding a way to construct `EntityGraph`s that resembles the new API for result set mappings, and the APIs for restrictions, etc, that we have been designing in the Data group. There's no good reason to need to go to the `EntityManager` to create a graph. (Hibernate already lets you instantiate one via a static method.)

So we could let you write something like:

```java
import static jakarta.peristence.EntityGraph.*;

...

graph(Book.class,
node(Book_.publisher,
graph(Publisher.class
node(Publisher_.whatever)
)
),
node(Book_authors)
)
```

or:

```java
import jakarta.peristence.*;

...

EntityGraph.of(Book.class,
Node.of(Book_.publisher,
Subgraph.of(Publisher.class
Node.of(Publisher_.whatever)
)
),
Node.of(Book_authors)
)
```

Or whatever. I have not yet put any thought into what it would really look like, it's just an idea that's been in the back of my head for quite a long time now.

This would just be a matter of adding maybe three `record` classes implementing those interfaces and some static methods to instantiate them. Perhaps one additional interface. Whatever.

Anyway, definitely not a high priority right now.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing EntityGraph API and the related result-set-mapping and restriction APIs mentioned in the issue. No files or tests are named; done would require an agreed factory API for constructing entity graph nodes, along with tests covering the proposed usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.