{"record":{"id":"945d610b6e8e73f9","repo":"quarkusio/quarkus","slug":"it-s-not-possible-to-compile-h2-triggers-when-embe","errorCode":null,"errorMessage":"It's not possible to compile H2 triggers when embedding the engine in GraalVM native images","messagePattern":"It's not possible to compile H2 triggers when embedding the engine in GraalVM native images","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions/jdbc/jdbc-h2/runtime/src/main/java/io/quarkus/jdbc/h2/runtime/graalvm/DisableSourceCompiler.java","lineNumber":21,"sourceCode":"import java.lang.reflect.Method;\n\nimport javax.script.CompiledScript;\nimport javax.script.ScriptException;\n\nimport com.oracle.svm.core.annotate.Substitute;\nimport com.oracle.svm.core.annotate.TargetClass;\n\n@Substitute\n@TargetClass(className = \"org.h2.util.SourceCompiler\")\npublic final class DisableSourceCompiler {\n\n    private static final String ERR = \"It's not possible to compile H2 triggers when embedding the engine in GraalVM native images\";\n\n    //Delete it all\n\n    @Substitute\n    public static boolean isJavaxScriptSource(String source) {\n        throw new UnsupportedOperationException(ERR);\n    }\n\n    @Substitute\n    public CompiledScript getCompiledScript(String packageAndClassName) throws ScriptException {\n        throw new UnsupportedOperationException(ERR);\n    }\n\n    @Substitute\n    public Class<?> getClass(String packageAndClassName)\n            throws ClassNotFoundException {\n        throw new UnsupportedOperationException(ERR);\n    }\n\n    @Substitute\n    public void setSource(String className, String source) {\n        //no-op\n    }\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/jdbc/jdbc-h2/runtime/src/main/java/io/quarkus/jdbc/h2/runtime/graalvm/DisableSourceCompiler.java#L3-L39","documentation":"Quarkus substitutes H2's SourceCompiler.isJavaxScriptSource with a stub that always throws UnsupportedOperationException when compiling a native image. H2's support for compiled (Java-source) triggers depends on the javax.script compiler, which cannot work in GraalVM native images because it generates and loads classes at runtime. This is an intentional hard failure to surface unsupported functionality at the point of use.","triggerScenarios":"Executing CREATE TRIGGER ... AS $JAVA_SOURCE$ (a compiled Java trigger) against an H2 database while the application runs as a GraalVM native image; H2 calls the substituted isJavaxScriptSource and hits the throw at DisableSourceCompiler.java:21.","commonSituations":"An app that works in JVM mode fails in native mode when a schema migration (Flyway/Liquibase) creates a Java-source trigger; test suites pass on JVM but a native CI job explodes at first DDL execution.","solutions":["Replace compiled Java triggers with standard SQL triggers or database-side logic supported in native images.","Move trigger creation out of native-mode startup/migrations, or gate Flyway/Liquibase locations per profile so native mode skips Java-trigger DDL.","Run that workload in JVM mode instead of native image.","Use an external Java component to implement the logic the trigger performed."],"exampleFix":"// before\nCREATE TRIGGER t BEFORE INSERT ON t FOR EACH ROW AS $JAVA_SOURCE$ ... $ // compiled trigger\n\n// after\nCREATE TRIGGER t BEFORE INSERT ON t FOR EACH ROW SET NEW.updated = NOW(); // SQL-only trigger","handlingStrategy":"fallback","validationCode":"if (ImageInfo.inImageRuntimeCode()) { /* avoid compiled-trigger DDL on H2 */ }","typeGuard":null,"tryCatchPattern":"try { stmt.execute(triggerDdl); } catch (UnsupportedOperationException e) { /* native mode: use SQL trigger instead */ }","preventionTips":["Never use H2 Java-source triggers in apps targeted for native compilation","Add a native-mode test that runs your schema migrations","Separate migration scripts for JVM and native profiles","Prefer plain SQL logic in H2 test databases"],"tags":["graalvm","native-image","h2","unsupported-operation"],"backgroundTag":"unsupported-in-native-image","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}