0

Is it possible to create a single application with Hibernate ORM and OGM? I created an application and I am getting issues for multiple JPA in a single application. I resolved this by changing the sessionFactory name for both JPA, still there is a conflict between two JPA. Below is the exception:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.data.neo4j.transaction.SharedSessionCreator#0': Unsatisfied dependency expressed through method 'createSharedSession' parameter 0: Could not convert argument value of type [org.hibernate.internal.SessionFactoryImpl] to required type [org.neo4j.ogm.session.SessionFactory]: Failed to convert value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.neo4j.ogm.session.SessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.neo4j.ogm.session.SessionFactory': no matching editors or conversion strategy found

Other error I am facing is:

Overriding bean definition for bean 'sessionFactory' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=databaseConfig; factoryMethodName=hibernate5SessionFactoryBean; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/company/nc/config/DatabaseConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=persistenceContext; factoryMethodName=sessionFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/company/nc/config/PersistenceContext.class]]

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.companyname</groupId>
    <artifactId>myprojectname</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <dependencies>


        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-ogm-http-driver</artifactId>
            <version>${neo4j-ogm.version}</version>
        </dependency>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-ogm-embedded-driver</artifactId>
            <version>${neo4j-ogm.version}</version>
        </dependency>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-ogm-bolt-driver</artifactId>
            <version>${neo4j-ogm.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>3.1.1</version>
            <scope>runtime</scope>
        </dependency>


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


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <!-- <version>3.8.1</version> -->
            <scope>test</scope>
        </dependency>

        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <!-- <version>4.2.5.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <!-- <version>4.2.5.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <!-- <version>4.2.5.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <!-- <version>4.2.5.RELEASE</version> -->
        </dependency>

        <!-- Spring AOP + AspectJ -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <!-- <version>4.2.5.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <!-- <version>1.6.11</version> -->
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <!-- <version>1.6.11</version> -->
        </dependency>

        <!-- JavaConfig need this library -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <!-- <version>2.7.3</version> -->
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <!-- <version>2.7.3</version> -->
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <!-- <version>2.7.3</version> -->
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <!-- <version>5.1.0.Final</version> -->
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <!-- <version>5.2.4.Final</version> -->
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <!-- <version>2.4.5</version> -->
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <!-- <version>5.1.38</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <!-- <version>4.0.4.RELEASE</version> -->
        </dependency>


        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <!-- <version>4.0.4.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.6.0</version>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
        </dependency>

        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
            <!-- <version>2.1</version> -->
        </dependency>


        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <!-- <version>2.3.1</version> -->
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

    </dependencies>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>


    <build>
        <finalName>myprojectname</finalName>

    </build>
</project>
Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • Could you please verify the pom content. Because this is a non-working maven configuration (`dependency` declaration outside `dependencies`) there might have been a problem when adding the content here. Additional it would be a big help if you provide your application configuration. And of course: Yes, it is totally fine to combine multiple stores within one application. – meistermeier Jan 26 '18 at 19:15
  • @meistermeier I am sorry for the confusion, I updated it manually for this question. I have shared my actual pom.xml now. – Vishrant Jan 26 '18 at 19:33
  • But how gets SpringData Neo4j into your project? I do not see any matching defined dependency. Part of your problem is an error in the creation of `org.springframework.data.neo4j.transaction.SharedSessionCreator` that is part of SpringData Neo4j. – meistermeier Jan 26 '18 at 20:25
  • @meistermeier seems like I have messed up with my imports. I have tried different approaches to connect with Neo4J. 1. Spring Data 2. Hibernate OGM. None seems to be working and there are conflict between the JPA which are created one for MySQL and one for Neo4J – Vishrant Jan 26 '18 at 20:29
  • I suspect the (JPA) `org.hibernate.internal.SessionFactoryImpl` to be registered with the name `sessionFactory` in the application context. This is also a bean that SpringData Neo4j expects to be created. – meistermeier Jan 26 '18 at 20:34
  • Yeah, seems like they are conflicting. Is there any way to separate them out? – Vishrant Jan 26 '18 at 20:37

1 Answers1

2

I'm one of the developer of the Hibernate OGM project.

I think something is not right in the dependencies. From your question it seems you are interested in Hibernate OGM but your pom is using Neo4j OGM.

If you want to use Hibernate ORM with Hibernate OGM, your pom should contain the following dependency:

    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-neo4j</artifactId>
        <version>${hibernateOgmVersion}</version>
    </dependency>

This will also include the required drivers and neo4j embedded. For more details about the configuration I'll let you to the documentation.

I think you should update the pom or update the question.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
  • thanks for answering, seems like I was importing incorrect dependencies, now I am using Neo4J OGM with Hibernate ORM. – Vishrant Jan 31 '18 at 20:24