{"record":{"id":"47bd6c20b06d9e0d","repo":"testcontainers/testcontainers-java","slug":"copying-database-folder-is-not-supported-for-neo4j-instances","errorCode":null,"errorMessage":"Copying database folder is not supported for Neo4j instances with version 4.0 or higher.","messagePattern":"Copying database folder is not supported for Neo4j instances with version 4\\.0 or higher\\.","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/neo4j/src/main/java/org/testcontainers/containers/Neo4jContainer.java","lineNumber":281,"sourceCode":"     * If you want to map your database into the container instead of copying them, please use {@code #withClasspathResourceMapping},\n     * but this will only work when your test does not run in a container itself.\n     * <br>\n     * Note: This method only works with Neo4j 3.5.\n     * <br>\n     * Mapping would work like this:\n     * <pre>\n     *      &#64;Container\n     *      private static final Neo4jContainer databaseServer = new Neo4jContainer&lt;&gt;()\n     *          .withClasspathResourceMapping(\"/test-graph.db\", \"/data/databases/graph.db\", BindMode.READ_WRITE);\n     * </pre>\n     *\n     * @param graphDb The graph.db folder to copy into the container\n     * @throws IllegalArgumentException If the database version is not 3.5.\n     * @return This container.\n     */\n    public S withDatabase(MountableFile graphDb) {\n        if (!isNeo4jDatabaseVersionSupportingDbCopy()) {\n            throw new IllegalArgumentException(\n                \"Copying database folder is not supported for Neo4j instances with version 4.0 or higher.\"\n            );\n        }\n        return withCopyFileToContainer(graphDb, \"/data/databases/graph.db\");\n    }\n\n    /**\n     * Adds plugins to the given directory to the container. If {@code plugins} denotes a directory, than all of that\n     * directory is mapped to Neo4j's plugins. Otherwise, single resources are copied over.\n     * <br>\n     * If you want to map your plugins into the container instead of copying them, please use {@code #withClasspathResourceMapping},\n     * but this will only work when your test does not run in a container itself.\n     *\n     * @param plugins\n     * @return This container.\n     */\n    public S withPlugins(MountableFile plugins) {\n        return withCopyFileToContainer(plugins, \"/var/lib/neo4j/plugins/\");","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/neo4j/src/main/java/org/testcontainers/containers/Neo4jContainer.java#L263-L299","documentation":"Neo4jContainer.withDatabase(MountableFile) copies a pre-built graph.db folder into the container, but that mechanism only works with Neo4j 3.5. From 4.0 onward the store format and directory layout changed, so the library rejects the call with an IllegalArgumentException rather than mounting an unusable database.","triggerScenarios":"Calling withDatabase(graphDbFolder) on a container configured with Neo4j image version 4.0 or newer (isNeo4jDatabaseVersionSupportingDbCopy() returns false).","commonSituations":"Upgrading tests from Neo4j 3.5 to 4.x/5.x while keeping the old database-seeding call; reusing seed fixtures created for 3.5 against a newer image tag.","solutions":["Pin the container image to neo4j:3.5 if you must seed via graph.db folder copy.","For 4.0+, seed data with Cypher scripts executed after startup (e.g. via the Bolt driver or container exec) instead of copying graph.db.","Use Neo4j admin dump/load inside the container for newer versions."],"exampleFix":"// before\nnew Neo4jContainer<>(\"neo4j:4.4\").withDatabase(MountableFile.forClasspathResource(\"graph.db\"));\n// after\nNeo4jContainer c = new Neo4jContainer<>(\"neo4j:4.4\");\nc.start();\n// run seed Cypher via driver at bolt://... after start","handlingStrategy":"validation","validationCode":"String tag = container.getDockerImageName();\nboolean supportsDbCopy = tag.contains(\":3.5\");\nif (!supportsDbCopy) {\n    // skip withDatabase(); seed via Cypher after start\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.withDatabase(graphDb);\n} catch (IllegalArgumentException e) {\n    // seed via Cypher through Bolt after container.start()\n}","preventionTips":["Only use withDatabase() with neo4j:3.5 images.","Adopt Cypher-based seeding for Neo4j 4.x/5.x.","Document the seeding strategy per image version in test infrastructure code."],"tags":["neo4j","version-incompatibility","database-seeding"],"backgroundTag":"unsupported-operation","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}