* @param wc
* @param <T>
* @return
*/
protected <T> Key<T> save(DBCollection dbColl, T entity, WriteConcern wc) {
MappedClass mc = mapr.getMappedClass(entity);
if (mc.getAnnotation(NotSaved.class) != null)
throw new MappingException("Entity type: " + mc.getClazz().getName() + " is marked as NotSaved which means you should not try to save it!");
WriteResult wr = null;
//involvedObjects is used not only as a cache but also as a list of what needs to be called for life-cycle methods at the end.
LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
DBObject dbObj = entityToDBObj(entity, involvedObjects);
//try to do an update if there is a @Version field
if (mc.hasVersioning()) {
wr = tryVersionedUpdate(dbColl, entity, dbObj, wc, db, mc);
} else {
if (wc == null)
wr = dbColl.save(dbObj);
else