commit dfaffebe56e92031a1224b5b9342ac8ff7eca3b9
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Fri Jul 24 01:22:30 2015 +0200

    fix in cache...drecksau^^

diff --git a/samples/example/main.cpp b/samples/example/main.cpp
index dec8a37..eef2f9e 100644
--- a/samples/example/main.cpp
+++ b/samples/example/main.cpp
@@ -51,15 +51,15 @@ int main(int argc, char *argv[]) {
                                          "Mustermann", Person::Gender::MALE));
     gPtr->setMainTeacher(mainTeacher);
     //Persons will also persisted
-    //e->create(groupPtr, true, true);
+    e->create(groupPtr, true, true);
 
     /** ---------------------------------
      * FIND Group
      * ---------------------------------
      */
-    QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
-    qDebug() << "Founded:" << foundMainTeacher->toString();
-    qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
+//    QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
+//    qDebug() << "Founded:" << foundMainTeacher->toString();
+//    qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
 
     QSharedPointer<Entity> groupFindPtr = e->findById<Group *>(1);
     QSharedPointer<Group> grp = groupFindPtr.objectCast<Group>();
@@ -75,7 +75,7 @@ int main(int argc, char *argv[]) {
     e->refresh(personFindPtr);
     QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
     qDebug()<< "MainTeacher:" << personFindPtr->toString();
-    qDebug() << "GroupSize:" << pers->getGroupsMainTeacher().size();
+    qDebug() << "GroupSize:" << pers->getMaintainedGroups().size();
 
 
 
diff --git a/src/cache.cpp b/src/cache.cpp
index 921f32b..13448a8 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -35,14 +35,14 @@ bool Cache::contains(const QString &key) {
 }
 
 void Cache::insert(QSharedPointer<Entity> &entity) {
-    if (entity.data() && entity->getId() > -1) {
+    if (entity && entity->getId() > -1) {
         QString key = this->generateKey(entity->getId(),
                                         QString(entity->getClassname()));
         if (this->cache.contains(key)) {
             QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
-            if (!ptr.isNull()) {
-                ptr.reset(entity.data());
-                entity = ptr;
+            if (ptr) {
+                ptr.swap(entity);
+                return;
             }
         }
         this->cache.insert(key, entity.toWeakRef());
@@ -63,7 +63,7 @@ QSharedPointer<Entity> Cache::get(qint64 id, const QString &classname) {
     QString key = this->generateKey(id, classname);
     if (this->contains(key)) {
         QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
-        if (!ptr.data()) {
+        if (!ptr) {
             this->remove(id, classname);
         }
         return ptr;
diff --git a/src/entity.h b/src/entity.h
index 3ed2846..4f1d079 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -41,7 +41,6 @@ class Entity : public QObject {
     void idChanged();
 
   public:
-    explicit Entity (QObject *parent = 0);
     virtual QString toString() const;
     virtual ~Entity();
     virtual QString getTablename() const;
@@ -70,6 +69,7 @@ class Entity : public QObject {
     void setId(const qint64 &value);
 
   protected:
+    explicit Entity (QObject *parent = 0);
     virtual QString slimToString() const;
     qint64 id;
 };
diff --git a/src/entityinstancefactory.cpp b/src/entityinstancefactory.cpp
index 885ae9d..ab76212 100644
--- a/src/entityinstancefactory.cpp
+++ b/src/entityinstancefactory.cpp
@@ -57,7 +57,7 @@ Entity *EntityInstanceFactory::createInstance(int metaTypeId) {
 
 Entity *EntityInstanceFactory::createInstance(const char *className,
         const QHash<QString, QVariant> &attributes) {
-    Entity *e = EntityInstanceFactory::createInstance(className);
+        Entity *e = EntityInstanceFactory::createInstance(className);
     e = EntityInstanceFactory::setAttributes(e, attributes);
     return e;
 }
@@ -88,8 +88,12 @@ Entity *EntityInstanceFactory::setAttributes(Entity *&e,
 
 Entity *EntityInstanceFactory::setAttributes(Entity *&e,
         const QHash<QString, QVariant> &attributes) {
+    if(!attributes.isEmpty()) {
     auto metaprops = e->getMetaProperties();
     return EntityInstanceFactory::setAttributes(e, attributes, metaprops);
+    } else {
+        return e;
+    }
 }
 
 const QString EntityInstanceFactory::extractEntityType(const QString &s) {
diff --git a/src/entitymanager.cpp b/src/entitymanager.cpp
index 3089b96..8506c44 100644
--- a/src/entitymanager.cpp
+++ b/src/entitymanager.cpp
@@ -164,8 +164,9 @@ QSharedPointer<Entity> EntityManager::findById(const qint64 &id,
 QSharedPointer<Entity> EntityManager::convert(const QHash<QString, QVariant>
         &map,
         const char *classname, const bool refresh) {
-    auto ptr = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
-                                          classname, map));
+    auto e = EntityInstanceFactory::createInstance(
+                 classname, map);
+    auto ptr = QSharedPointer<Entity>(e);
     this->cache.insert(ptr);
     this->resolveRelations(ptr, map, refresh);
     return ptr;
