Re: [Neo4j] Declarative transaction management with SpringRestGraphDatabase

187 views
Skip to first unread message
Message has been deleted

Michael Hunger

unread,
Oct 8, 2012, 12:41:25 PM10/8/12
to ne...@googlegroups.com
First of all, there are no transactions over the http-interface.

There is a mode of the java-rest-bindings that take all operations within a tx-boundary and send them to the server as a single batch-request. But it has some shortcomings, e.g. not allowing reads of the data you've just written and others. 

So SDN uses the non-tx (or tx per request mode) of the REST API, so that there are no real transactional guarantees in this mode.

SpringRestGraphDatabase actually extends AbstractGraphDatabase, so the error that pops up is unexpected. Can you post the full exception?

Which versions of SDN and Neo4j are you using?


Michael

Am 08.10.2012 um 11:03 schrieb tims83:

Hi,

I'm using the Neo4j, spring-data-neo4j and spring-data-neo4j-rest projects and I'm trying to configure declarative transaction management. The documentation suggests that I add the following:

<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 mode="aspectj" transaction-manager="neo4jTransactionManager"/>

<neo4j:config graphDatabaseService="graphDatabaseService" />

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>

When I run this configuration, I'm getting the following exception:

org.springframework.data.neo4j.rest.SpringRestGraphDatabase cannot be cast to org.neo4j.kernel.AbstractGraphDatabase

This leaves me clueless on how to configure the declarative transaction management. Does this happen because a transaction can span over multiple REST calls to the server? Any advice would be much appreciated.

Thanks,
Timmy

--
 
 

tims83

unread,
Oct 9, 2012, 3:38:32 AM10/9/12
to ne...@googlegroups.com
Thanks for your reply. I'm using SDN version 2.0.1.RELEASE and Neo4J version 1.6.3. When I use version 1.7.2 or 1.8 of Neo4J, I'm getting another exception (see below). But probably this makes sense right, since declarative transaction management cannot be used when using the REST approach. I understand that it's one transaction per request. If multiple requests are made in a single method, they would all run in a different transaction. Any ideas on what a good approach would be to handle situations like this? What if one of those calls fails?

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.neo4j.kernel.impl.transaction.SpringTransactionManager#19713ea' defined in URL [file:/applicationContext-db.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.neo4j.kernel.GraphDatabaseAPI]: Could not convert constructor argument value of type [org.springframework.data.neo4j.rest.SpringRestGraphDatabase] to required type [org.neo4j.kernel.GraphDatabaseAPI]: Failed to convert value of type 'org.springframework.data.neo4j.rest.SpringRestGraphDatabase' to required type 'org.neo4j.kernel.GraphDatabaseAPI'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.data.neo4j.rest.SpringRestGraphDatabase] to required type [org.neo4j.kernel.GraphDatabaseAPI]: no matching editors or conversion strategy found

Thanks,
Timmy

Michael Hunger

unread,
Oct 9, 2012, 3:55:21 AM10/9/12
to ne...@googlegroups.com
Timmy,

to use Neo4j 1.7 or 1.8 you should upgrade to SDN 2.1.RC4.

If you want to encapsulate multiple operations in one call you can either use a cypher statement which contains the operations that you want to execute.

Or you use the RestAPI.executeBatch() method which records your calls within the callback and then sends them all over in a single rest-batch-operation (which is executed in a single tx) and fills in read-values after the request returns.

See:


HTH

Michael

--
 
 

tims83

unread,
Oct 9, 2012, 4:58:33 AM10/9/12
to ne...@googlegroups.com
Thanks Michael! I'm going to play around with it. ;-)
Reply all
Reply to author
Forward
0 new messages