I would propose to make your two foreign keys a composite primary key.
Your association entity would be identified by the ids of its two relations.
Theorically, Doctrine's UnitOfWork/CommitOrderCalculator should be albe to insert elements in correct order, and thus, you wouldn't have to deal with persist order.
Your mapping would look like this at the end (annotation example):
<?php
class UserGroup
{
/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\Id
**/
public $user;
/**
* @ORM\ManyToOne(targetEntity="Group")
* @ORM\Id
**/
public $group;
}