cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Use both neo4j and postgres in same project

madiskou
Graph Buddy

Hello,

I use sdn rx library and i have a postgres database also, i want to know if i can use the 2 db in the same project ?

Thank you

6 REPLIES 6

mike2
Node Clone

Yes you can, do you have any specific questions about it? I just wrote a python script that connects to Postgres, reads all the data from my Postgres database and wrote it to Neo4j without any issues.

webtic
Graph Fellow

Yes using both complementary to each other is perfectly ok.

madiskou
Graph Buddy

I have in a service with two transactional operations, the first with a neo4j and the second with postgres like this :

neo4jService.addAlertLabel(alert);
alert.setEndDate(new Timestamp(receivedAlert.getTimestamp()*1000));
alertRepository.save(alert);

addAlertLabel(alert) will add a label to a node in the neo4j graph
alertRepository.save(alert) will save an entity in the postgres db

the operation with neo4j is good but the seconde operation (the save in postgres) does not work (i have no error but it don't find the entity in the db)

I use the sdn rx library, before when i used neo4j-java-driver it worked well.

Do you use @Transactional on your methods? This should make both transaction managers (Neo4j and JPA(?)) aware of an ongoing Spring transaction and they will share their state information.

madiskou
Graph Buddy

yes i tried @Transactional i have this error :


Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.transaction.TransactionManager' available: expected single matching bean but found 2: transactionManager,reactiveTransactionManager

@Transactional from springframework transaction or javax.transaction ?

Sorry for the delayed answer:
We checked back and it is not as simple as I thought. You would need to declare a third TransactionManager. To be more precise it should be a (named) ChainedTransactionManager that will take the JPA/JDBC and Neo4j transaction manager. You will then have to declare this transaction manager in the annotation like @Transactional("myChainedTxManager").