vladmihalcea / hypersistence-optimizer

Hypersistence Optimizer allows you to get the most out of JPA and Hibernate. By scanning your application configuration and mappings, Hypersistence Optimizer can tell you what changes you need to do to speed up your data access layer.
https://vladmihalcea.com/hypersistence-optimizer/
Apache License 2.0
318 stars 43 forks source link

ClassCastException: class sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to class java.lang.Class #250

Closed pergravgaard closed 2 months ago

pergravgaard commented 2 months ago

The stack trace error:

java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.TypeVariableImpl and java.lang.Class are in module java.base of loader 'bootstrap')
    at io.hypersistence.optimizer.hibernate.scanner.Hibernate63MappingScanner$4.execute(Hibernate63MappingScanner.java:247) ~[hypersistence-optimizer-2.9.0-jakarta.jar:?]
    at io.hypersistence.optimizer.core.action.ActionExecutor.execute(ActionExecutor.java:68) ~[hypersistence-optimizer-2.9.0-jakarta.jar:?]
    at io.hypersistence.optimizer.hibernate.scanner.Hibernate63MappingScanner.scanBasicIdentifierGenerator(Hibernate63MappingScanner.java:203) ~[hypersistence-optimizer-2.9.0-jakarta.jar:?]
    at io.hypersistence.optimizer.hibernate.scanner.Hibernate63MappingScanner.scanEntityIdentifier(Hibernate63MappingScanner.java:188) ~[hypersistence-optimizer-2.9.0-jakarta.jar:?]

The method that is failing is scanCompositeIdentifierGenerator.

The problem seems to be caused by the following mapping:

@MappedSuperclass
public abstract class AbstractEntity<ID extends Serializable> implements Persistable<ID> {

    @Id
    @GeneratedValue(
            strategy = GenerationType.AUTO
    )
    @Column(nullable = false, unique = true, updatable = false)
    private ID id;
...
}
vladmihalcea commented 2 months ago

@pergravgaard I will need the entity mapping that triggers this issue. Since the scanCompositeIdentifierGenerator method failed, it means the entity mapping is using some composite identifier, which I will need in order to replicate the problem.

pergravgaard commented 2 months ago

Sorry, somehow I got confused by my IDE and copied the wrong method. The method causing the issue is actually scanBasicIdentifierGenerator.

I believe you can reproduce with an entity like this:

@Entity
public class Role extends AbstractEntity<Long> {
...
}
vladmihalcea commented 2 months ago

Fixed.

pergravgaard commented 2 months ago

Thank you very much. That' was quick.

:-) Per

Sent with Proton Mail secure email.

On Wednesday, 11 September 2024 at 7:23 PM, Vlad Mihalcea @.***> wrote:

Fixed.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

vladmihalcea commented 2 months ago

@pergravgaard You're welcome. Let me know if the 2.10.1 version fixes the problem.

pergravgaard commented 2 months ago

It does, already checked it. And if my memory is correct the issue wasn't there prior to version 2.8.x, but it could also be due to the fact that I upgraded my project to Spring Boot 3 and maybe another HibernateScanner class was used after that.

:-) Per

Sent with Proton Mail secure email.

On Thursday, 12 September 2024 at 10:04 AM, Vlad Mihalcea @.***> wrote:

@.***(https://github.com/pergravgaard) You're welcome. Let me know if the 2.10.1 version fixes the problem.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>