try{
Transaction tx = graphDb.beginTx();
}

========>

try(Transaction tx = graphDb.beginTx())
{
}