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
306 stars 43 forks source link

HypersistenceHibernatePersistenceProvider cannot resolve the SessionFactoryDecorator constructor #182

Closed hannibal218bc closed 1 year ago

hannibal218bc commented 1 year ago

I'm trying to setup this tool for a Hibernate 4.3 project (native - no Spring, no JPA, no Jakarta; runs on Java 11/12 with hypersistence-optimizer-2.6.0-trial-jre6.jar), but run into this exception when calling HypersistenceHibernatePersistenceProvider.decorate( this.sessionFactoryHibernate ):

java.lang.NoSuchMethodException: io.hypersistence.optimizer.hibernate.decorator.Hibernate43SessionFactoryDecorator.<init>(org.hibernate.SessionFactory)
    at java.base/java.lang.Class.getConstructor0(Class.java:3354)
    at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2558)
    at io.hypersistence.optimizer.util.ReflectionUtils.newInstance(ReflectionUtils.java:144)
    at io.hypersistence.optimizer.util.ReflectionUtils.newInstance(ReflectionUtils.java:89)
    at io.hypersistence.optimizer.hibernate.decorator.HypersistenceHibernatePersistenceProvider.decorate(HypersistenceHibernatePersistenceProvider.java:76)

And it's true, the Hibernate43SessionFactoryDecorators only constructor is declared as Hibernate43SessionFactoryDecorator(org.hibernate.engine.spi.SessionFactoryImplementor delegate);

The actual type of the session factory being passed is org.hibernate.internal.SessionFactoryImpl, which implements SessionFactoryImplementor so the call should have worked, it seems that just the constructor lookup is wrong?

Thanks!

vladmihalcea commented 1 year ago

Can you provide a replicating test case with the setup you tried so I could investigate it?

hannibal218bc commented 1 year ago

I had hoped you'd say that it's clearly the Hibernate43SessionFactoryDecorator constructor that need to be changed... ;-)

Alright, I'll try to come up with an example project, thanks!

hannibal218bc commented 1 year ago

Hi again,

here's the test case: https://github.com/Handig-Eekhoorn/Hypersistence-Tests

You should be able to run it by mvn compile exec:java. The result will be the exception posted above. Thank you for investigating!

vladmihalcea commented 1 year ago

Thanks. In the meantime, you can skip the decoration part, as that's only needed for Runtime events.

You can just pass the undecorated SessionFactory to the Optimizer configuration.

vladmihalcea commented 1 year ago

@hannibal218bc I managed to replicate the issue.

vladmihalcea commented 1 year ago

Fixed.

hannibal218bc commented 1 year ago

Fixed.

Awesome, thank you!

vladmihalcea commented 1 year ago

It's now available in the Full Version and I'm now merging to the Trial.

vladmihalcea commented 1 year ago

@hannibal218bc The fix is now available in the Trial Version as well.

hannibal218bc commented 1 year ago

I've already bought the license earlier today ;+)

vladmihalcea commented 1 year ago

@hannibal218bc Thanks, and enjoy using it.