# Same Java code for server database and for embedded database

**URL:** <https://community.neo4j.com/t/same-java-code-for-server-database-and-for-embedded-database/35875>\
**Category:** Cypher\
**Created:** [March 25, 2021, 8:39pm UTC](https://community.neo4j.com/t/same-java-code-for-server-database-and-for-embedded-database/35875 "2021-03-25T20:39:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![depire](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/depire/32/5915_2.png) [@depire](https://community.neo4j.com/u/depire)\
**Post date:** [March 25, 2021, 8:39pm UTC](https://community.neo4j.com/t/same-java-code-for-server-database-and-for-embedded-database/35875/1 "2021-03-25T20:39:58Z")

</div>

Dear all,

I would like to know if some guys have developped Java codes running correclty on a server database AND an embedded database.  
I have a server with a neo4j database, I have developped some Java codes using Cypher (no OGM). My idea is to create an sandbox using embedded neo4j database in Java.  
I want to re-use my Java code on the embedded database.  
But I have a problem, my codes is written like that:

```
		Transaction tx = session.beginTransaction();
		String command = "MATCH ()-[r:REL]-() WHERE id(r) = " + id + " DELETE r";
		tx.run(command);
		tx.commit();
		tx.close();

```

where   
driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password), config);  
session = driver.session();

I have the following code for embedded part:  
File databaseDirectory = new File(home+"/Downloads/NEO4J");  
DatabaseManagementService managementService = new DatabaseManagementServiceBuilder( databaseDirectory.toPath() ).build();  
graphDb = managementService.database( DEFAULT\_DATABASE\_NAME );

The problem is that graphDb has a method beginTx() returning a Transaction,  
as session.beginTransaction(), but there is not the same class:  
server version uses: org.neo4j.graphdb.Transaction  
embedded version uses: org.neo4j.driver.Transaction

Do you have any idea ?

Thanks

---

<div class="post-metadata">

**Author:** ![elena.kohlwey](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/elena.kohlwey/32/31033_2.png) [@elena.kohlwey](https://community.neo4j.com/u/elena.kohlwey)\
**Post date:** [March 26, 2021, 2:29pm UTC](https://community.neo4j.com/t/same-java-code-for-server-database-and-for-embedded-database/35875/2 "2021-03-26T14:29:27Z")

</div>

Hi,

I cannot directly solve your problem, however, I stumbled upon some code that uses and exectues a cypher-file for an embedded database. Maybe that might help you.

[neo4j-procedure-template/TraverseDemoTest.java at 4.2 · neo4j-examples/neo4j-procedure-template · GitHub](https://github.com/neo4j-examples/neo4j-procedure-template/blob/4.2/src/test/java/example/TraverseDemoTest.java) (ll. 29-37)

Regards,  
Elena
