Fix infinite loop in unit of work 

The issue takes place when you have a bi-directional reference between 2 classes that have both a discriminator map and that are also both owning side (because no owning/inversed side has been specified). When building the dependencies in the unit of work, it'll loop between both classes and generate an out of memory crash.

I've simply added a check to avoid adding dependencies that already exist and thus avoid the loop. I've also added a functional test that provokes the loop issue.