Skip to content

AnnotationBasedPersistentProperty cannot resolve Id properties [Wrong Id class used] #3283

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

Open
SledgeHammer01 opened this issue May 4, 2025 · 2 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@SledgeHammer01
Copy link

SledgeHammer01 commented May 4, 2025

BasicPersistentEntity::returnPropertyIfBetterIdPropertyCandidateOrNull
--> AnnotationBasedPersistentProperty::isIdProperty

https://github.com/spring-projects/spring-data-commons/blob/main/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java#L78-L79

Shouldn't the Id.class used here be jakarta.persistence.id?

Otherwise the RelationalEntityMetadata doesn't contain the id column.

@SledgeHammer01 SledgeHammer01 changed the title AnnotationBasedPersistentProperty cannot resolve Id properties AnnotationBasedPersistentProperty cannot resolve Id properties [Wrong Id class used] May 4, 2025
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 4, 2025
@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label May 5, 2025
@mp911de
Copy link
Member

mp911de commented May 5, 2025

Not sure I follow. RelationalEntityMetadata is part of the Spring Data Relational module (not JPA) and thus it doesn't use the Jakarta Persistence API annotations. Care to elaborate the actual issue, ideally by providing a reproducer or code snippet to illustrate the usecase?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 5, 2025
@SledgeHammer01
Copy link
Author

SledgeHammer01 commented May 5, 2025

Not sure I follow. RelationalEntityMetadata is part of the Spring Data Relational module (not JPA) and thus it doesn't use the Jakarta Persistence API annotations. Care to elaborate the actual issue, ideally by providing a reproducer or code snippet to illustrate the usecase?

I am building a Spring Boot Starter for Hibernate Reactive. So I have a HibernateReactiveQueryMethod class for string and PartTree based queries.

My getEntityInformationMethod() override looks like:

 @Override
  @SuppressWarnings("unchecked")
  public RelationalEntityMetadata<?> getEntityInformation() {
    if (this.metadata == null) {
      Class<?> returnedObjectType = getReturnedObjectType();
      Class<?> domainClass = getDomainClass();

      if (ClassUtils.isPrimitiveOrWrapper(returnedObjectType)
          || ReflectionUtils.isVoid(returnedObjectType)) {
        this.metadata =
            new SimpleRelationalEntityMetadata<>(
                (Class<Object>) domainClass,
                this.mappingContext.getRequiredPersistentEntity(domainClass));
      } else {
        RelationalPersistentEntity<?> returnedEntity =
            this.mappingContext.getPersistentEntity(returnedObjectType);

        RelationalPersistentEntity<?> managedEntity =
            this.mappingContext.getRequiredPersistentEntity(domainClass);

        returnedEntity =
            ((returnedEntity == null) || returnedEntity.getType().isInterface())
                ? managedEntity
                : returnedEntity;

        RelationalPersistentEntity<?> tableEntity =
            domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity : managedEntity;

        this.metadata =
            new SimpleRelationalEntityMetadata<>(
                (Class<Object>) returnedEntity.getType(), tableEntity);
      }
    }

    return this.metadata;
  }

the entityMetadata.getTableEntity().getIdColumn() doesn't work because the entity will be using jakarta.persistence.Id, but stepping through the Spring code, it is looking for the org.springframework.data.annotation.Id.

Possible its supposed to work like that since this is internal Spring stuff, but seemed logical that getEntityInformation() should pick up the @Id column on the entity? I made that assumption since it picks up all the other stuff from the entity annotations, just not the id column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants