Skip to content

Expose the ID of an entity via EntityRepository and BaseEntityService - #77

Merged
BalusC merged 3 commits into
developfrom
feature/72-get-id
Nov 3, 2026
Merged

BalusC merged 3 commits into
developfrom
feature/72-get-id

Conversation

@BalusC

@BalusC BalusC commented Nov 3, 2026

Copy link
Copy Markdown
Member

EntityRepository#getId(E) returns the ID of an entity, also when the entity does not implement Identifiable:

  • via the persistence provider when the entity is a proxy;
  • else via Identifiable#getId() when the entity implements it;
  • else via the ID attribute from the metamodel.

It returns null when the entity has no ID, e.g. when it has a generated ID and is not persisted yet.

BaseEntityService#getId(E) is protected, like getIdentifierType() and isGeneratedId(), which EntityRepository also exposes publicly. A subclass of BaseEntityService which already has its own method named getId with another signature may now clash with it.

No accessor for the name of the ID attribute is added: criteria and ordering on "id" already resolve to the actual ID attribute.

New ITs in EntityRepositoryIT cover an entity without BaseEntity (before and after persist, and a lazy reference, which is a proxy on Hibernate) and an Identifiable entity. All tests pass on H2 with Hibernate, EclipseLink and OpenJPA.

Fixes #72

🤖 Generated with Claude Opus 5.5

BalusC and others added 3 commits November 3, 2026 09:31
EntityRepository#getId(E) returns the ID of an entity which need not
implement Identifiable: via the persistence provider when it is a
proxy, else via Identifiable#getId() when it implements it, else via
its ID attribute. BaseEntityService#getId(E) is protected, like the
other accessors which EntityRepository exposes publicly.

Fixes #72

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BalusC
BalusC merged commit de12f94 into develop Nov 3, 2026
3 checks passed
@BalusC
BalusC deleted the feature/72-get-id branch November 3, 2026 13:54
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

Successfully merging this pull request may close these issues.

1 participant