I have a User entity that has Lazy relations
@JoinTable(name = "user_identities", joinColumns = {
@JoinColumn(name = "user_id")}, inverseJoinColumns = {
@JoinColumn(name = "user_identity_id")})
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true)
private Set<Identity> identities;
@JoinTable(name = "user_roles", joinColumns = {
@JoinColumn(name = "user_id")}, inverseJoinColumns = {
@JoinColumn(name = "role_id")})
@OneToMany(fetch = FetchType.LAZY)
private Set<Role> roles;
I execute hibernate
@Query("SELECT u FROM User u JOIN u.identities i JOIN FETCH u.roles r WHERE i.sub = :sub AND i.issuer = :issuer")
Optional<User> findByIdentitySubAndIssuer(String sub, String issuer);
In jvm mode (not native) everything works fine, but in native image, i am getting the following error:
Generation of HibernateProxy instances at runtime is not allowed when the configured BytecodeProvider is 'none'; your model requires a more advanced BytecodeProvider to be enabled..
I am using spring boot 3.1.0
Hibernate version 6.2.2 Final
I was trying to enable hibernate enhancer, adding to properties jpa: properties: hibernate: enhancer: enable: true
which resulted in another exception on application startup in native mode Failed to initialize JPA EntityManagerFactory: Default-resolver threw exception Could not instantiate named strategy class [org.hibernate.boot.model.relational.ColumnOrderingStrategyStandard]
UPDATE: with id 'org.springframework.boot' version '3.0.7' and id 'org.hibernate.orm' version "6.1.7.Final
still getting In Spring native: Generation of HibernateProxy instances at runtime is not allowed when the configured BytecodeProvider
Please help. tnx
As described in this Spring issue, you need to provide bytecode enhancement at build time through hibernate-enhance-maven-plugin
gradle
plugins {
id "org.hibernate.orm" version "<version-to-use>"
}
hibernate {
enhancement {
lazyInitialization true
}
}
maven
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>$currentHibernateVersion</version>
<executions>
<execution>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Also consider that in latest Hibernate version 6.2, enableLazyInitialization param used in the plugin has been deprecated and enabled by default : HHH-15641
For more information about bytecode enhancement see Hibernate docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With