Uploaded image for project: 'Hibernate OGM'
  1. OGM-1263

org.hibernate.ogm.datastore.neo4j.Neo4jDialect does not work with spring

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.1.0.Final
    • Fix Version/s: None
    • Component/s: neo4j
    • Environment:
      Windows 10, Neo4j 3.1.1, hibernate-ogm-bom 5.1.4.Final
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true
    • Sprint:

      Description

      I get the following error which prevents the application to run

      01:03:07.488 [main] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit '60Capital-neo4j-ejbPU' 
      .01:03:07.505 [main] INFO  o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
      	name: 60Capital-neo4j-ejbPU
      	...] 
      .01:03:07.584 [main] INFO  org.hibernate.Version - HHH000412: Hibernate Core {5.0.9.Final} 
      .01:03:07.586 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found 
      .01:03:07.587 [main] INFO  org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist 
      .01:03:07.640 [main] INFO  o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 
      .01:03:10.566 [main] WARN  o.h.e.j.e.i.JdbcEnvironmentInitiator - HHH000342: Could not obtain connection to query metadata : Could not instantiate named strategy class [org.hibernate.ogm.datastore.neo4j.Neo4jDialect] 
      .01:03:10.570 [main] WARN  o.s.c.a.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.dcubedev.config.Neo4jJpaPersistenceContext: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
      Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.dcubedev.config.Neo4jJpaPersistenceContext: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
      	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
      	at com.dcubedev.neo4j_sdn.App.main(App.java:183)
      Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
      	at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
      	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
      	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
      	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
      	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
      	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
      	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
      	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
      	... 11 more
      Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Could not instantiate named strategy class [org.hibernate.ogm.datastore.neo4j.Neo4jDialect]
      	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:170)
      	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:126)
      	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:120)
      	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74)
      	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51)
      	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
      	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
      	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
      	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
      	... 27 more
      Caused by: java.lang.InstantiationException: org.hibernate.ogm.datastore.neo4j.Neo4jDialect
      	at java.lang.Class.newInstance(Unknown Source)
      	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:166)
      	... 35 more
      Caused by: java.lang.NoSuchMethodException: org.hibernate.ogm.datastore.neo4j.Neo4jDialect.<init>()
      	at java.lang.Class.getConstructor0(Unknown Source)
      	... 37 more
      

      Here is the code to create emf

      private Properties hibProperties() {
              Properties properties = new Properties();
              //properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, "org.hibernate.ogm.datastore.neo4j.HttpNeo4jDialect"); // new as of 5.1.0.final
              properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, "org.hibernate.ogm.datastore.neo4j.Neo4jDialect");
              //properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT_NEO4J));
              properties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
              return properties;
          }
          
          @Bean
          public DataSource dataSource() {
          	System.out.println("Neo4jJpaPersistenceContext::dataSource() Environment env: " + env);
          	// capital60
          	// matalan
          	// mysql:mysql-connector-java:jar
              DriverManagerDataSource dataSource = new DriverManagerDataSource("jdbc:neo4j:http://localhost:7474", "stephen", "demo2017");
       
              dataSource.setDriverClassName("org.neo4j.jdbc.http.HttpDriver");
              //dataSource.setUrl("jdbc:neo4j:http://localhost:7474");
              //dataSource.setUsername("stephen");
              //dataSource.setPassword("demo2017");
       
              return dataSource;
          }
          
      	@Bean
      	public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
      		//String persistenceXmlLocation = "C:/workspace/dcube-groups/dcube-groups/src/main/resources/persistence.xml";
      		String persistenceXmlLocation = "persistence.xml";
      		String persistenceUnitName = "60Capital-neo4j-ejbPU";
      		System.out.println("Neo4jJpaPersistenceContext::entityManagerFactory() ... " );
      		System.out.println("Neo4jJpaPersistenceContext::entityManagerFactory() Environment env: " + env);
      
      		HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      		System.out.println("Neo4jJpaPersistenceContext::entityManagerFactory() vendorAdapter: " + vendorAdapter);
      		vendorAdapter.setGenerateDdl(true);
      
      		LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
      		System.out.println("Neo4jJpaPersistenceContext::entityManagerFactory() LocalContainerEntityManagerFactoryBean factory: " + factory);
      		factory.setJpaVendorAdapter(vendorAdapter);
      		factory.setPackagesToScan("com.dcubedev.domain.neo4j");
      		factory.setDataSource(dataSource());
      		factory.setPersistenceXmlLocation(persistenceXmlLocation);
      		factory.setPersistenceUnitName(persistenceUnitName);
      		
      		factory.setJpaProperties(hibProperties());
      		
      		System.out.println("Neo4jJpaPersistenceContext::entityManagerFactory() factory.getObject(): " + factory.getObject());
      		return factory;
      	}
      
      	@Bean
      	public PlatformTransactionManager transactionManager() {
      
      		JpaTransactionManager txManager = new JpaTransactionManager();
      		txManager.setEntityManagerFactory(entityManagerFactory().getObject());
      		//txManager.setEntityManagerFactory(entityManagerFactory());
      		return txManager;
      	}
      

      Here is persistence.xml

      <persistence-unit name="60Capital-neo4j-ejbPU"
      		transaction-type="RESOURCE_LOCAL">
      		<!-- Use the Hibernate OGM provider: configuration will be transparent -->
      		<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
      		<exclude-unlisted-classes>false</exclude-unlisted-classes>
      		<properties>
      		    <property name="hibernate.ogm.datastore.provider" value="neo4j_http"/>
      		    <property name="hibernate.connection.driver_class" value="org.neo4j.jdbc.http.HttpDriver" />
      			<property name="hibernate.connection.url" value="jdbc:neo4j:http://localhost:7474" />
      			<property name="hibernate.ogm.datastore.host" value="localhost:7474" />
      			<property name="hibernate.ogm.datastore.username" value="neo4j" />
      			<property name="hibernate.ogm.datastore.password" value="demo2017" />
      			<property name="hibernate.ogm.neo4j.database_path" value="C:/neo4j/database/tutorial" />
      			<!-- http://docs.jboss.org/hibernate/core/4.0/javadocs/org/hibernate/service/jta/platform/internal/package-summary.html 
      			<property name="hibernate.transaction.jta.platform"
      				value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
      			-->
      		</properties>
      	</persistence-unit>
      

      Maven

      <properties>
      		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      		<spring.version>4.3.6.RELEASE</spring.version>
      		<mysql.version>5.1.40</mysql.version>
      		<jackson-core-version>2.8.3</jackson-core-version>
      		<release-train>Ingalls-RELEASE</release-train>
      		<neo4j.version>3.1.1</neo4j.version>
      		<logback.version>1.2.1</logback.version>
      		<jcloverslf4j.version>1.7.23</jcloverslf4j.version>
      	</properties>
      
      <dependencyManagement>
      		<dependencies>
      
      			<dependency>
      				<groupId>org.springframework</groupId>
      				<artifactId>spring-framework-bom</artifactId>
      				<version>${spring.version}</version>
      				<scope>import</scope>
      				<type>pom</type>
      			</dependency>
      
      			<dependency>
      				<groupId>org.springframework.data</groupId>
      				<artifactId>spring-data-releasetrain</artifactId>
      				<version>${release-train}</version>
      				<scope>import</scope>
      				<type>pom</type>
      			</dependency>
      
      			<dependency>
      				<groupId>org.hibernate.ogm</groupId>
      				<artifactId>hibernate-ogm-bom</artifactId>
      				<version>5.1.4.Final</version>
      				<type>pom</type>
      				<scope>import</scope>
      			</dependency>
      
      		</dependencies>
      
      	</dependencyManagement>
      
      	<dependencies>
      	<!-- hibernate -->
      		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
      		<dependency>
      			<groupId>org.hibernate</groupId>
      			<artifactId>hibernate-core</artifactId>
      		</dependency>
      		
      		<!-- Hibernate OGM hibernate-ogm-neo4j module; pulls in the OGM core module -->
      		<dependency>
      			<groupId>org.hibernate.ogm</groupId>
      			<artifactId>hibernate-ogm-neo4j</artifactId>
      		</dependency>
      		
      <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
      		<dependency>
      			<groupId>org.springframework.data</groupId>
      			<artifactId>spring-data-jpa</artifactId>
      		</dependency>
      
      		<dependency>
      			<groupId>org.neo4j</groupId>
      			<artifactId>neo4j-kernel</artifactId>
      			<version>${neo4j.version}</version>
      		</dependency>
      
      		<dependency>
      			<groupId>org.neo4j</groupId>
      			<artifactId>neo4j-jdbc-http</artifactId>
      			<version>3.0.1</version>
      		</dependency>
      
      		<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api 
      			<dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> 
      			<version>1.0</version> </dependency> -->
      
      		<!-- standard APIs dependencies - provided in a Java EE container -->
      		<dependency>
      			<groupId>org.hibernate.javax.persistence</groupId>
      			<artifactId>hibernate-jpa-2.1-api</artifactId>
      		</dependency>
      
      		<dependency>
      			<groupId>javax.transaction</groupId>
      			<artifactId>jta</artifactId>
      			<version>1.1</version>
      		</dependency>
      

        Attachments

        1. DemoJpaService.java
          0.6 kB
        2. JpaMysqlPersistenceContext.java
          6 kB
        3. JpaNeo4jPersistenceContext.java
          3 kB
        4. MainApp.java
          5 kB
        5. MainApp.java
          3 kB

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: