javahibernatequarkussoft-delete

Cannot load from object array because "this.tableMappings" is null - Quarkus Hibernate


The problem

Hello everybody, I'm trying to add the @SoftDelete annotation to one of my entities. When doing so, my quarkus application won't start anymore producing the following error message:

2024-04-13 14:23:34,828 DEBUG [org.hib.orm.mod.map.creation] (JPA Startup Thread) Starting PostInitCallbackEntry : Entity(com.yannjeanmaire.api.ephemeria.entities.Shop) `staticFetchableList` generator
2024-04-13 14:23:34,828 DEBUG [org.hib.orm.sql.ast.create] (JPA Startup Thread) Created new SQL alias : s1_0
2024-04-13 14:23:34,828 DEBUG [org.hib.orm.mod.map.creation] (JPA Startup Thread) Mapping-model creation encountered (possibly) transient error : java.lang.NullPointerException: Cannot load from object array because "this.tableMappings" is null
2024-04-13 14:23:34,829 DEBUG [org.hib.orm.mod.map.creation] (JPA Startup Thread) Starting PostInitCallbackEntry : Entity(com.yannjeanmaire.api.ephemeria.entities.Shop) `staticFetchableList` generator
2024-04-13 14:23:34,829 DEBUG [org.hib.orm.sql.ast.create] (JPA Startup Thread) Created new SQL alias : s1_0
2024-04-13 14:23:34,829 DEBUG [org.hib.orm.mod.map.creation] (JPA Startup Thread) Mapping-model creation encountered (possibly) transient error : java.lang.NullPointerException: Cannot load from object array because "this.tableMappings" is null
2024-04-13 14:23:34,829 DEBUG [org.hib.int.SessionFactoryImpl] (JPA Startup Thread) HHH000031: Closing
2024-04-13 14:23:34,830 DEBUG [org.hib.ser.int.AbstractServiceRegistryImpl] (JPA Startup Thread) Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries
2024-04-13 14:23:34,831 DEBUG [org.hib.boo.reg.int.BootstrapServiceRegistryImpl] (JPA Startup Thread) Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries
2024-04-13 14:23:34,841 DEBUG [org.hib.orm.beans] (Quarkus Main Thread) HHH10005004: Stopping BeanContainer : io.quarkus.hibernate.orm.runtime.cdi.QuarkusArcBeanContainer@18b0a908
2024-04-13 14:23:34,848 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile [dev]): java.lang.RuntimeException: Failed to start quarkus
    at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
    at io.quarkus.runtime.Application.start(Application.java:101)
    at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:111)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:71)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
    at io.quarkus.runner.GeneratedMain.main(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:113)
    at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: <default>] Unable to build Hibernate SessionFactory
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.persistenceException(FastBootEntityManagerFactoryBuilder.java:129)
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:89)
    at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
    at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
    at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:154)
    at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:61)
    ... 1 more
Caused by: java.lang.IllegalStateException: PostInitCallback queue could not be processed...
        - PostInitCallbackEntry - Entity(com.yannjeanmaire.api.ephemeria.entities.Shop) `staticFetchableList` generator

    at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:144)
    at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.execute(MappingModelCreationProcess.java:88)
    at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.process(MappingModelCreationProcess.java:42)
    at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:198)
    at org.hibernate.internal.SessionFactoryImpl.initializeMappingModel(SessionFactoryImpl.java:364)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:293)
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:87)
    ... 6 more
    Suppressed: java.lang.NullPointerException: Cannot load from object array because "this.tableMappings" is null
        at org.hibernate.persister.entity.AbstractEntityPersister.getTableMapping(AbstractEntityPersister.java:2889)
        at org.hibernate.persister.entity.SingleTableEntityPersister.getIdentifierTableDetails(SingleTableEntityPersister.java:470)
        at org.hibernate.persister.entity.AbstractEntityPersister.getSoftDeleteTableDetails(AbstractEntityPersister.java:5907)
        at org.hibernate.persister.entity.AbstractEntityPersister.createRootTableGroup(AbstractEntityPersister.java:3113)
        at org.hibernate.loader.ast.internal.LoaderSelectBuilder.buildRootTableGroup(LoaderSelectBuilder.java:578)
        at org.hibernate.loader.ast.internal.LoaderSelectBuilder.generateSelect(LoaderSelectBuilder.java:494)
        at org.hibernate.loader.ast.internal.LoaderSelectBuilder.createSelect(LoaderSelectBuilder.java:257)
        at org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor.<init>(GeneratedValuesProcessor.java:71)
        at org.hibernate.persister.entity.AbstractEntityPersister.createGeneratedValuesProcessor(AbstractEntityPersister.java:2012)
        at org.hibernate.persister.entity.AbstractEntityPersister.lambda$prepareMappingModel$12(AbstractEntityPersister.java:5033)
        at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess$PostInitCallbackEntry.process(MappingModelCreationProcess.java:246)
        at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:106)
        ... 12 more

Press [space] to restart, [e] to edit command line args (currently ''), [r] to resume testing, [o] Toggle test output, [h] for more options>
2024-04-13 14:23:34,920 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure

Definition of the entity

@SoftDelete
public class Shop {
    public static final int PREFIX_LENGTH = 3;

    @Id
    @GeneratedValue
    @Column(name = "id_shop")
    private UUID idShop;

    @Column(nullable = false)
    private String name;

    @Column(length = PREFIX_LENGTH, unique = true, nullable = false)
    private String prefix;

    @Column(nullable = false)
    private LocalDateTime openedOn;

    private LocalDateTime archivedOn;

    @Column(nullable = false)
    private LocalDateTime createdOn;

    @UpdateTimestamp(source = SourceType.DB)
    private LocalDateTime lastUpdateOn;

    @ManyToMany(mappedBy = "shops")
    private Set<User> users = new HashSet<>();
    
    ...
}

User entity (only the join part)

public class User {
    ...
    @ManyToMany(cascade = CascadeType.PERSIST)
    @JoinTable(
            name = "user_shop",
            joinColumns = {@JoinColumn(name = "id_application_user")},
            inverseJoinColumns = {@JoinColumn(name = "id_shop")})
    private final Set<Shop> shops = new HashSet<>();
    ...
}

Config Details

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ttt</groupId>
    <artifactId>ttt</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <compiler-plugin.version>3.12.1</compiler-plugin.version>
        <maven.compiler.release>17</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>3.9.3</quarkus.platform.version>
        <skipITs>true</skipITs>
        <surefire-plugin.version>3.2.3</surefire-plugin.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5-mockito</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-jdbc-h2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-openapi</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-keycloak-admin-resteasy-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-oidc</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-keycloak-admin-resteasy-client -->

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-keycloak-authorization</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-test-keycloak-server</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-jdbc-postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-health</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-test-h2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-hibernate-orm-panache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.14.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.7</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>2.40.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <formats>
                        <format>
                            <includes>
                                <include>.gitattributes</include>
                                <include>.gitignore</include>
                            </includes>
                            <trimTrailingWhitespace/>
                            <endWithNewline/>
                            <indent>
                                <tabs>true</tabs>
                                <spacesPerTab>4</spacesPerTab>
                            </indent>
                        </format>
                    </formats>
                    <java>
                        <cleanthat/>
                        <googleJavaFormat>
                            <version>1.18.1</version>
                            <style>GOOGLE</style>
                            <reflowLongStrings>true</reflowLongStrings>
                            <formatJavadoc>false</formatJavadoc>
                        </googleJavaFormat>
                        <indent>
                            <tabs>true</tabs>
                            <spacesPerTab>2</spacesPerTab>
                        </indent>
                        <importOrder/>
                        <removeUnusedImports/>
                        <licenseHeader>
                            <content>/* (C)$YEAR */</content>
                        </licenseHeader>
                    </java>
                </configuration>
            </plugin>
            <plugin>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.platform.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <systemPropertyVariables>
                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner
                        </native.image.path>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <properties>
                <skipITs>false</skipITs>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>

I've tried

I'll take any advice, thank you!


Solution

  • Since I posted this answer, I have been able to reproduce the issue and it seems that it came from the @UpdateTimestamp(source = SourceType.DB).

    I tried to switch it to @UpdateTimestamp(source = SourceType.VM) (also equal to UpdateTimestamp) and it worked.

    I've opened an issue here: Quarkus GitHub Issues

    Have a nice day!