Skip to content
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

[4.x] Hibernate app fails to run (Native Image) #8096

Closed
lprimak opened this issue Dec 3, 2023 · 20 comments · Fixed by #8740
Closed

[4.x] Hibernate app fails to run (Native Image) #8096

lprimak opened this issue Dec 3, 2023 · 20 comments · Fixed by #8740
Assignees
Labels
4.x Version 4.x bug Something isn't working examples native-image P2
Projects
Milestone

Comments

@lprimak
Copy link

lprimak commented Dec 3, 2023

Environment Details

  • Helidon Version: 4.0.5
  • Helidon MP
  • JDK version: 21.0.2-graalce
  • OS: Mac

Problem Description

Sample JPA/JTA app fails to start with the following exception:

% ./target/database-mp 
2023.12.02 23:04:36 INFO io.helidon.logging.jul.JulProvider Thread[#1,main,5,main]: Logging at runtime configured using classpath: /logging.properties
2023.12.02 23:04:36 INFO org.hibernate.jpa.internal.util.LogHelper Thread[#1,main,5,main]: HHH000204: Processing PersistenceUnitInfo [name: pu1]
2023.12.02 23:04:36 INFO org.hibernate.cache.internal.RegionFactoryInitiator Thread[#1,main,5,main]: HHH000026: Second-level cache disabled
Exception in thread "main" org.hibernate.boot.registry.selector.spi.StrategySelectionException: Default-resolver threw exception
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:223)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:180)
	at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:746)
	at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:140)
	at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:164)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:277)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:198)
	at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:35)
	at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:102)
	at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:169)
	at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:142)
	at io.helidon.integrations.cdi.jpa.PersistenceExtension.produceEntityManagerFactory(PersistenceExtension.java:1409)
	at org.jboss.weld.bootstrap.events.configurator.BeanConfiguratorImpl$CreateCallback.create(BeanConfiguratorImpl.java:372)
	at org.jboss.weld.bootstrap.events.configurator.BeanConfiguratorImpl$ImmutableBean.create(BeanConfiguratorImpl.java:511)
	at org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96)
	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:679)
	at org.jboss.weld.bean.builtin.InstanceImpl.getBeanInstance(InstanceImpl.java:262)
	at org.jboss.weld.bean.builtin.InstanceImpl$InstanceImplIterator.next(InstanceImpl.java:335)
	at io.helidon.integrations.cdi.jpa.JpaExtension.onStartup(JpaExtension.java:2053)
	at java.base@21.0.1/java.lang.reflect.Method.invoke(Method.java:580)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
	at org.jboss.weld.injection.MethodInvocationStrategy$DefaultMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:144)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
	at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:126)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
	at jakarta.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:142)
	at org.jboss.weld.util.Observers.notify(Observers.java:166)
	at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
	at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
	at org.jboss.weld.event.EventImpl.fire(EventImpl.java:96)
	at io.helidon.microprofile.cdi.HelidonContainerImpl.doStart(HelidonContainerImpl.java:317)
	at io.helidon.common.context.Contexts.runInContext(Contexts.java:137)
	at io.helidon.microprofile.cdi.HelidonContainerImpl.start(HelidonContainerImpl.java:256)
	at io.helidon.microprofile.cdi.Main.main(Main.java:80)
	at io.helidon.microprofile.cdi.CdiStartupProvider.start(CdiStartupProvider.java:39)
	at io.helidon.Main.main(Main.java:63)
	at java.base@21.0.1/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Could not instantiate named strategy class [org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard]
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:244)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:180)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:167)
	at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl$2.call(MetadataBuilderImpl.java:752)
	at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl$2.call(MetadataBuilderImpl.java:749)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:220)
	... 40 more
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Could not instantiate named strategy class [org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard]
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.lambda$static$0(StrategySelectorImpl.java:41)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:240)
	... 45 more
Caused by: java.lang.InstantiationException: org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard
	at java.base@21.0.1/java.lang.Class.newInstance(DynamicHub.java:719)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.lambda$static$0(StrategySelectorImpl.java:37)
	... 46 more
Caused by: java.lang.NoSuchMethodException: org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard.<init>()
	at java.base@21.0.1/java.lang.Class.checkMethod(DynamicHub.java:1065)
	at java.base@21.0.1/java.lang.Class.getConstructor0(DynamicHub.java:1228)
	at java.base@21.0.1/java.lang.Class.newInstance(DynamicHub.java:706)
	... 47 more

Steps to reproduce

  • Use Helidon CLI to create brand new database MP application
  • mvn package -Pnative-image

Run the resulting binary, and you will see the error.

@github-actions github-actions bot added this to Triage in Backlog Dec 3, 2023
@lprimak
Copy link
Author

lprimak commented Dec 3, 2023

@m0mus m0mus added bug Something isn't working native-image examples 4.x Version 4.x P2 labels Dec 6, 2023
@m0mus m0mus moved this from Triage to High priority in Backlog Dec 6, 2023
@lprimak
Copy link
Author

lprimak commented Dec 11, 2023

Any help would be appreciated. I’m eager to use Helidon MP for a command-line JPA application.

Thank you.

@ljnelson
Copy link
Member

My personal situation prevents me from engaging at work full time at the moment, but my immediate thought is that the strategy in question is a class that Graal's native image analysis did not identify. Just a guess. I'm not a huge Graal guy (or fan) but there are various switches and whatnot where you can tell it, "oh, also consider this class when you're doing your closed-world analysis". So my guess is if you add this strategy to it…? Good luck.

@lprimak
Copy link
Author

lprimak commented Dec 11, 2023

Thanks Laird,

I have tried to solve this problem on my own but was not successful. After solving the initial org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard issue, a bunch of others came up.
I spent 2 days on it but had to give up figuring someone smarter / more experienced in this than I can figure it out :)
Or, I have missed something simple...

I do know that Quarkus solved this somehow so it can be done...

@lprimak
Copy link
Author

lprimak commented Dec 11, 2023

For reference, Here is my PoC Greeter project (Weld-SE, Helidon, Quarkus)
Helidon has optional JPA by turning on the profile (mvn -Phelidon-jpa package)
https://github.com/flowlogix/native-java
which uses my repackaged Weld (same as Helidon one, but using Weld 5.1.2 and GraalVM substitutions)
https://github.com/flowlogix/weld-se-native

@lprimak
Copy link
Author

lprimak commented Jan 2, 2024

Maybe @tomas-langer can take a look? Thank you!

@barchetta barchetta modified the milestones: 4.0.3, 4.0.4 Jan 3, 2024
@m0mus m0mus moved this from High priority to Legendary in Backlog Jan 11, 2024
@m0mus m0mus moved this from Legendary to Sprint Scope in Backlog Jan 11, 2024
@tomas-langer
Copy link
Member

There were some quite major changes done in Hibernate, that broke its usability in native image (at least for us, without doing some major changes).
We will investigate this, if there is an easy solution.
I am trying to reproduce the problem with latest Helidon (4.0.3), which has an upgraded version of Hibernate. This version no longer supports none bytecode provider, and fails at build time of native image with the following:

Caused by: org.hibernate.HibernateException: Using the ReflectionOptimizer is not possible when the configured BytecodeProvider is 'none'. Use a different BytecodeProvider
        at org.hibernate.bytecode.internal.none.BytecodeProviderImpl.getReflectionOptimizer(BytecodeProviderImpl.java:48)

and if the property is removed:

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'net.bytebuddy.implementation.bind.annotation.Argument$Binder' was found in the image heap. This type...

Byte buddy should not be reachable in this case at all.

We will try to investigate possible solutions.

@tomas-langer
Copy link
Member

I have opened issue https://hibernate.atlassian.net/browse/HHH-17650 in Hibernate, as the approach we used to use is no longer valid. I hope there is an easy solution for this, as it is used from other projects that use native image...

@barchetta barchetta modified the milestones: 4.0.4, 4.1.0 Jan 18, 2024
@lprimak
Copy link
Author

lprimak commented Jan 18, 2024

Thanks for looking at this Tomas! I am glad it's not just something silly I missed.

@lprimak
Copy link
Author

lprimak commented Jan 18, 2024

Just saw the Hibernate bug, and it looks like maybe the fix is near :) Hopefully Helidon will be compatible with Hibernate 6.4.1+ :)

@ljnelson
Copy link
Member

Watch hibernate/hibernate-orm#7714

@tomas-langer
Copy link
Member

Current required workarounds to make this work in Helidon (we will fix it properly once the Hibernate issue gets resolved):

  1. Add src/main/resources/META-INF/helidon/native-image/reflection-config.json with the following content:
{
    "class-hierarchy": [
        "org.hibernate.boot.model.relational.ColumnOrderingStrategy"
    ],
    "classes": [
        "org.hibernate.boot.beanvalidation.TypeSafeActivator",
        "org.hibernate.dialect.H2Dialect"
    ]
}
  1. Update (or add) to src/main/resources/META-INF/groupId/artifactId/native-image.properties (this may not be needed post fix):
Args=--initialize-at-build-time=net.bytebuddy

@lprimak
Copy link
Author

lprimak commented Feb 5, 2024

Tried the new Hibernate release (6.4.3.Final), the above-mentioned patch, and both.
Unfortunately it still didn't work and had the same failures :(

@lprimak
Copy link
Author

lprimak commented Feb 7, 2024

Unfortunately, same problems with the new Helidon release (4.0.5)

@lprimak
Copy link
Author

lprimak commented Mar 30, 2024

Hi,

Any updates on this would be appreciated.
Looks like milestone is 4.1, is this still the case?
Thank you

@tvallin
Copy link
Member

tvallin commented Apr 12, 2024

Hi,
I was able to make it work with current hibernate 6.3.1.Final but my fix is not production ready yet.
So next step is to discuss with the team how to properly implement this fix and release it as soon as possible.
Concerning the milestone, it is still planed for 4.1.

@romain-grecourt
Copy link
Contributor

romain-grecourt commented May 8, 2024

Found another ticket that looks like a duplicate of the one Tomas filed: https://hibernate.atlassian.net/browse/HHH-17568.
It's been fixed by hibernate/hibernate-orm#7753 which is available as of 6.5.0.CR1.

I tried 6.5.0.Final and the issue with the none bytecode provider went away.

@ljnelson
Copy link
Member

ljnelson commented May 8, 2024

Isn't returning null what it did originally? That was the right call all along.

@lprimak
Copy link
Author

lprimak commented May 13, 2024

Will there be a pre-release of 4.1 I can test with?

@romain-grecourt romain-grecourt modified the milestones: 4.1.0, 4.0.9 May 13, 2024
@romain-grecourt
Copy link
Contributor

This will be included in 4.0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working examples native-image P2
Projects
Backlog
  
Closed
Development

Successfully merging a pull request may close this issue.

7 participants