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

Description

I get the following error which prevents the application to run

Here is the code to create emf

Here is persistence.xml

Maven

Environment

Windows 10, Neo4j 3.1.1, hibernate-ogm-bom 5.1.4.Final

Activity

Show:
Davide D'Alto
March 9, 2017, 9:33 AM

Great, I'll close the issue then

kwadwo boahen
March 15, 2017, 2:33 PM

Davide,

After several experimentation, I realized the main problem is that some
how, Hibernate is looking for only entityManagerFactory regardless of what
has been configured. I configured entityManagerFactory but named the bean
"entityManagerFactoryJpaNeo4j". The thing is I have data in Mysql which I
want to migrate to Neo4j. I cannot have both the Mysql and Neo4j instances
named entityManagerFactory. Hibernate complains it does not see a
unique entityManagerFactory when I name both instances entityManagerFactory.

What do you suggest I do, open a new issue or you can re-open the old issue?

I have attached my changes to your demo project.

Thanks

Stephen

.10:19:35.787 [main] INFO org.hibernate.Version - HHH000412: Hibernate
Core {5.1.4.Final}
.10:19:35.789 [main] INFO org.hibernate.cfg.Environment - HHH000206:
hibernate.properties not found
.10:19:35.792 [main] INFO org.hibernate.cfg.Environment - HHH000021:
Bytecode provider name : javassist
.10:19:35.883 [main] INFO o.h.annotations.common.Version - HCANN000001:
Hibernate Commons Annotations {5.0.1.Final}
.10:19:36.136 [main] INFO o.h.o.d.i.DatastoreProviderInitiator -
OGM000016: NoSQL Datastore provider:
org.hibernate.ogm.datastore.neo4j.remote.http.impl.HttpNeo4jDatastoreProvider
.10:19:36.937 [main] INFO o.h.o.d.impl.GridDialectInitiator - OGM000017:
Grid Dialect: org.hibernate.ogm.datastore.neo4j.HttpNeo4jDialect
.10:19:36.939 [main] INFO o.h.o.d.impl.GridDialectInitiator - Grid dialect
logs are disabled
.10:19:36.945 [main] INFO o.h.o.d.impl.GridDialectInitiator - OGM000017:
Grid Dialect: org.hibernate.ogm.datastore.neo4j.HttpNeo4jDialect
.10:19:36.946 [main] INFO o.h.o.d.impl.GridDialectInitiator - Grid dialect
logs are disabled
.10:19:36.962 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using
dialect: org.hibernate.ogm.dialect.impl.OgmDialect
.10:19:36.987 [main] INFO o.h.e.j.e.i.LobCreatorBuilderImpl - HHH000422:
Disabling contextual LOB creation as connection was null
.10:19:37.524 [main] INFO o.h.validator.internal.util.Version - HV000001:
Hibernate Validator 5.0.0.Final
.10:19:37.823 [main] INFO org.hibernate.ogm.cfg.impl.Version - OGM000001:
Hibernate OGM 5.1.0.Final
.10:19:38.123 [main] INFO o.h.o.t.impl.OgmJtaPlatformInitiator -
OGM000076: No explicit or implicit defined JTAPlatform. Using NoJtaPlatform
.10:19:40.167 [main] WARN o.h.o.d.n.i.BaseNeo4jSchemaDefiner - OGM001404:
Neo4j does not support constraints spanning multiple columns. Unique key
gen_idPK for gen_id on columns [application, extra_info, primary_key]
cannot be created
.10:19:40.341 [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 'capital60JpaNeo4jServiceImpl': Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire
field: com.dcubedev.neo4j.repository.CapitalMemberJpaNeo4jRepository
com.dcubedev.neo4j.action.Capital60JpaNeo4jServiceImpl.capitalMemberJpaRepository;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'capitalMemberJpaNeo4jRepository': Cannot create inner bean
'(inner bean)#245253d8' of type
[org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean
property 'entityManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name '(inner bean)#245253d8': Cannot resolve reference to bean
'entityManagerFactory' while setting constructor argument; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'entityManagerFactory' is defined
.10:19:40.341 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean -
Closing JPA EntityManagerFactory for persistence unit
'60Capital-neo4j-ejbPU'
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'capital60JpaNeo4jServiceImpl': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire
field: com.dcubedev.neo4j.repository.CapitalMemberJpaNeo4jRepository
com.dcubedev.neo4j.action.Capital60JpaNeo4jServiceImpl.capitalMemberJpaRepository;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'capitalMemberJpaNeo4jRepository': Cannot create inner bean
'(inner bean)#245253d8' of type
[org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean
property 'entityManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name '(inner bean)#245253d8': Cannot resolve reference to bean
'entityManagerFactory' while setting constructor argument; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'entityManagerFactory' is defined
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at
org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
at com.dcubedev.app.MainApp.main(MainApp.java:68)
Caused by: org.springframework.beans.factory.BeanCreationException: Could
not autowire field:
com.dcubedev.neo4j.repository.CapitalMemberJpaNeo4jRepository
com.dcubedev.neo4j.action.Capital60JpaNeo4jServiceImpl.capitalMemberJpaRepository;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'capitalMemberJpaNeo4jRepository': Cannot create inner bean
'(inner bean)#245253d8' of type
[org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean
property 'entityManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name '(inner bean)#245253d8': Cannot resolve reference to bean
'entityManagerFactory' while setting constructor argument; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'entityManagerFactory' is defined
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 12 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'capitalMemberJpaNeo4jRepository': Cannot create
inner bean '(inner bean)#245253d8' of type
[org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean
property 'entityManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name '(inner bean)#245253d8': Cannot resolve reference to bean
'entityManagerFactory' while setting constructor argument; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'entityManagerFactory' is defined
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 14 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#245253d8': Cannot resolve reference
to bean 'entityManagerFactory' while setting constructor argument; nested
exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'entityManagerFactory' is defined
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at
org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
... 27 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'entityManagerFactory' is defined
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 35 more

On Thu, Mar 9, 2017 at 4:33 AM, Davide D'Alto (JIRA) <

Davide D'Alto
March 15, 2017, 2:40 PM

I will re-open this isuue

Davide D'Alto
March 22, 2017, 5:26 PM

Can you publish your persistence.xml? I'm not sure I understand the new issue.

kwadwo boahen
March 22, 2017, 6:05 PM

Here is the persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="60Capital-ejbPU"
transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/capital60" />
<property name="hibernate.connection.username" value="stephen" />
<property name="hibernate.connection.password" value="demo2016" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
</persistence-unit>
<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.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>
</persistence>

The issue is Hibernate does not allow an application to have more than 1 instance of an entity manager/entity manager factory like other JPA frameworks eg EclipseLink. For example I am able to create and use multiple instances in EclipseLink but not in Hibernate like so:

define

@Bean(name="entityManagerFactory")
public EntityManagerFactory entityManagerFactory() {
return entityManagerFactoryJpaMysqlLocal().getObject();
}

@Bean(name="entityManagerFactoryNeo4j")
public EntityManagerFactory entityManagerFactoryNeo4j() {
return entityManagerFactoryJpaNeo4jLocal().getObject();
}

Use

@Autowired
@Qualifier("entityManagerFactory")
EntityManagerFactory emfMysql;

@Autowired
@Qualifier("entityManagerFactoryNeo4j")
EntityManagerFactory emfNeo4j;

Assignee

Davide D'Alto

Reporter

kwadwo boahen

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

Yes, likely

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

Priority

Major
Configure