If you're not using entities but Native SQL as shown here then you might want to get the last inserted id as shown below:
$entityManager->getConnection()->lastInsertId()
For databases with sequences such as PostgreSQL please note that you can provide the sequence name as the first parameter of the lastInsertId
method.
$entityManager->getConnection()->lastInsertId($seqName = 'my_sequence')
For more information take a look at the code on GitHub here and here.