Announcement Announcement Module
Collapse
No announcement yet.
JPA and Neo4j in same app, no cross store domains Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA and Neo4j in same app, no cross store domains

    I have had this working before in another application. But for some reason the same configuration is not working in my current application.

    So I have Spring Data JPA and Spring Data Neo4j in my project.

    I have a separate JPATransactionManager with id of transactionManager. But whenever I try calling my JPA repositories and do some save, I get "not in a transaction" exceptions.

    I have integration tests, where the only difference is that the integration tests config files only have Spring Data JPA in it and not pointing to any Spring Data Neo4j config files.

    Here is my config for SDN

    Code:
        <util:properties id="neo4jProperties" location="classpath:META-INF/spring/neo4j.properties"/>
    
        <neo4j:config graphDatabaseService="graphDatabaseService"/>
    
        <bean id="graphDatabaseService"
        	class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
          <constructor-arg index="0" value="#{neo4jProperties['neo4j.location']}" />
        </bean>
    
        <neo4j:repositories base-package="com.blah.account.repository.neo4j"/>
    
        <bean id="neo4jTransactionManager"
        	   class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="transactionManager">
                <bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
                    <constructor-arg ref="graphDatabaseService"/>
                </bean>
            </property>
            <property name="userTransaction">
                <bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
                    <constructor-arg ref="graphDatabaseService"/>
                </bean>
            </property>
        </bean>
    
        <tx:annotation-driven/>
    And my Spring Data JPA config

    Code:
        <util:properties id="postgresProperties" location="classpath:META-INF/spring/postgres.properties"/>
    
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
        <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource">
            <property name="portNumber" value="#{postgresProperties['postgres.port']}"/>
            <property name="user" value="#{postgresProperties['postgres.username']}"/>
            <property name="password" value="#{postgresProperties['postgres.password']}"/>
            <property name="serverName" value="#{postgresProperties['postgres.url']}"/>
            <property name="databaseName" value="#{postgresProperties['postgres.databasename']}"/>
            <property name="initialConnections" value="5"/>
            <property name="maxConnections" value="25"/>
        </bean>
    
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="jpaVendorAdapter" ref="jpaAdapter"/>
            <property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
            </property>
            <property name="persistenceUnitName" value="hdpoker"/>
            <property name="packagesToScan">
                <list>
                    <value>com.blah.account</value>
                </list>
            </property>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>
    
        <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="POSTGRESQL"/>
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true"/>
        </bean>
    
        <jpa:repositories base-package="com.blah.account.repository.jpa" entity-manager-factory-ref="entityManagerFactory"/>
    Thanks for your help.

    Mark

  • #2
    I changed the name of the transactionManager to "jpaTransactionManager, removed the neo4jTransactionManager that was defined.

    Moved my <tx:annotation-driven> to the rdbms config file and set its transactionManager-ref attribute to point to jpaTransactionManager and now it works.

    Mark

    Comment

    Working...
    X