cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

General Understanding: Spring + OGM for multiple databases?

Hi!

I'm a hobby genealogist and used neo4j with OGM for my bachelor thesis to build a genealogy application, supporting multiple database folders (which worked correctly)

Because of the very good implementation of repositories (and custom queries) in Spring Data, I tried to switch, but I cannot get my code to work.

It seems like I have some issues with the general understanding on how Springs Repositories work: I don't want a temporary database to startup with the appliation, but to start up after you selected it on a splash screen (or created a new file) and inject the repositories then.

Is that possible with Neo4j-OGM and Spring? If yes, how can I setup the Spring Application to not load an embeddeddriver on startup and rather load an embedded driver when I need it (with a specific database folder attached)?

Sorry if the question is unclear, but my code is too complicated to create a minimal working example (due to JavaFX and everything) - maybe someone can nudge me in the right direction?

Thanks in advance!

Greetings from Germany,

Nico

// EDIT : At the moment, my pom.xml looks like this:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-neo4j</artifactId>
    </dependency>

    <!-- Neo4j -->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>3.5.9</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-core</artifactId>
        <version>3.1.14</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-embedded-driver</artifactId>
        <version>3.1.14</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-bolt-driver</artifactId>
        <version>3.1.14</version>
        <scope>compile</scope>
    </dependency>

My full code (which does not work at the moment) is here: https://github.com/niclemon/geneagraph)

1 REPLY 1

Hi,

unfortunately what you want to do is not possible with the Spring Data modules. All Spring beans get created on startup. This also includes the Java driver bean with its configuration.

Danger zone (thinks might explode 😞
However it is possible to destroy and create new beans during runtime in a Spring application. TBH I never tried this with SDN and the Java driver bean.
A second approach could be that you first start a launcher application that then calls the real application with e.g. (temporary) environment variables to create the Java driver bean from.

If I would have to choose I think I would go with the second option. Both are not really nice but I wanted to give you some possible solutions.