Results 1 to 10 of 12

Thread: Spring Data Neo4j transactions mixed with Hibernate transactions

Hybrid View

  1. #1

    Question Spring Data Neo4j transactions mixed with Hibernate transactions

    Hi

    I have a project with a bunch of relational tables mapped with hibernate, using spring managed transactions and everything was working fine until I added Spring Data Neo4j. After that, I could interact with my Neo4j graph db but cannot write to my relational db. No exception, no warning, nothing. Just the request hangs in the call to a method marked with @Transactional.

    I supose that I need to handle differently the transactions, but can't find how to do that.

    Is there a wat yo make SDN transactions work together with Hibernate transactions?

    Thanks in advance

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Could you try to use @Neo4jTransactional or @Transactional("neo4jTransactionManager")

    Neo4j defines a transaction manager and only aliases it as transactionManager but your hibernate tx-manager bean definition named "transactionManager" should have precedence.

  3. #3

    Default

    That's exactly the problem, the hibernate transactionManager doesn't take precedence.

    My workaround was to copy the class Neo4jConfiguration, remove the transactionManager alias and use @Neo4jTransactional. With this I can use both transactions managers, but I really don't want to have my own version of that class. What can I do to avoid that conflict?
    Last edited by leonardo.moreno; Apr 25th, 2012 at 10:34 AM.

  4. #4
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I thought the Neo4J transaction manager was a JTA transactionManager. Or maybe you can define a JTA Transaction Manager and wrap the two transaction managers in the JTA one, and then name the JTA one "transactionManager" I had to do something along these lines to have both Spring Data Neo4J and Spring Batch (which has relational tables) in my project.

    Mark

  5. #5
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Yeah, I had put this in my config

    Code:
    <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>
            <property name="allowCustomIsolationLevels" value="true"/>
        </bean>
    And I have

    Code:
    <beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <beans:property name="dataSource" ref="dataSource"/>
        </beans:bean>
    for Jdbc to the Batch tables, in order to get both Neo4J and Batch to work together.

    Hope that helps

    Mark

  6. #6

    Default

    Hi Mark, thanks for your time.

    How did you configure neo4j? with <neo4j:config ...>? Because the problem I have is that the Neo4JConfiguration class declares the transaction manager with 2 aliases neo4jTransactionManager and transactionManager and because hibernate looks for the bean named transactionManager, it hangs when trying to the obtain a transaction.

    If that is going to generate a conflict the developers must be aware of that, don't you think?

    Leonardo

  7. #7
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Quote Originally Posted by leonardo.moreno View Post
    Hi Mark, thanks for your time.

    How did you configure neo4j? with <neo4j:config ...>? Because the problem I have is that the Neo4JConfiguration class declares the transaction manager with 2 aliases neo4jTransactionManager and transactionManager and because hibernate looks for the bean named transactionManager, it hangs when trying to the obtain a transaction.

    If that is going to generate a conflict the developers must be aware of that, don't you think?

    Leonardo
    Yeah, I made a bean for my GraphDatabaseService. So I have

    Code:
    <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
                destroy-method="shutdown">
            <constructor-arg index="0" value="${neo4j.location}"/>
            <constructor-arg index="1">
                <map>
                    <entry key="allow_store_upgrade" value="${neo4j.upgrade}"/>
                </map>
            </constructor-arg>
        </bean>
    
        <neo4j:config graphDatabaseService="graphDatabaseService"/>
    
        <neo4j:repositories base-package="com.perfectworldprogramming.eventgate"/>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •