Difference between org.neo4j.graphdb.GraphDatabaseService.beginTx() and org.neo4j.driver.Session.beginTransaction()

Dear all,

I work on a Neo4j server with java, so I develop codes based on org.neo4j.driver.Session.beginTransaction() (Java driver).

My methods are written as follows:
public doSomething(arg) {
Transaction tx = this.getTransaction();
tx.run(command);
tx.commit();
tx.close();
}

I want to use the same methods doSomething for embedded database.
I would like to write a method

// Server Db
private Session session;
// Embedded Db
private GraphDatabaseService graphDb;

private Transaction getTransaction(boolean servertype) {
	
	if (servertype) {
		return session.beginTransaction();
	} else {
		System.out.println("Mode Embedded");
		return (Transaction) graphDb.beginTx();
	}
}

Transaction is returned class but it is two different classes in fact,
How to convert/use one for the other and vice-versa ?

Best regards,
Alexandre