Skip to content

[OPENJPA-3107] Populate the class_ field of a generated static metamodel - #337

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-3107
Open

rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-3107

Conversation

@rzo1

@rzo1 rzo1 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/OPENJPA-3107

Since 4.2.0 (OPENJPA-2940) the annotation processor generates the JPA 3.2 field public static volatile EntityType<Foo> class_; (or MappedSuperclassType / EmbeddableType) in every canonical metamodel class. MetamodelImpl.populate() treated it as an attribute and failed with meta-field-less-param, so any persistence unit with a generated metamodel failed on the first getCriteriaBuilder() / getMetamodel().

MetamodelImpl.populate():

  • class_ is set to the managed type. For a class that is both an entity and an embeddable, the embeddable type is used if the field can hold it, otherwise the entity type.
  • static final constants (QUERY_, MAPPING_) and fields that are not attributes, such as the TypedQueryReference and EntityGraph fields other generators emit, are skipped.
  • The error message for a mismatching field names that field and its own type; it no longer fails with an NPE or reports the previous field. Wildcard types are printed instead of failing with a ClassCastException.

AnnotationProcessor6 (also from OPENJPA-2940):

  • Query or mapping names that map to the same constant name (e.g. Coll.byName and Coll.byname) failed the generation of the whole class. The first one is kept and a warning is logged.
  • Constant values are written as escaped Java string literals.

Tests (persistence/meta/constants): the _ classes are the exact processor output, and metamodelMatchesProcessorOutput runs AnnotationProcessor6 and compares its output with them. Covered: entity, mapped superclass, embeddable, a class that is entity and embeddable, inherited metamodel classes, named query and mapping constants, a Criteria query through class_, a Hibernate 7 style metamodel, wrong class_ types and mismatching fields. 11 of 12 fail on master.

Set class_ to the managed type and skip constants and fields that are
not attributes. Keep the first of two named query or mapping constants
with the same name in the annotation processor.

Generated-by: Claude Code (Opus 5.5)
@rzo1
rzo1 marked this pull request as ready for review December 4, 2026 06:32
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.

2 participants