You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/07/18 18:07:52 UTC

[13/15] [OLINGO-366, OLINGO-367, OLINGO-370] chahnged entity, entity collection and complex creation methods (still missing complex collection creator). Provided delayed HTTP request for navigation property. Provided select query option support on entity s

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
index be6d446..6359459 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
@@ -24,6 +24,7 @@ import org.apache.olingo.ext.proxy.utils.ClassUtils;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import org.apache.olingo.ext.proxy.Service;
 
 class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implements OperationExecutor {
 
@@ -34,11 +35,11 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
   private final AbstractStructuredInvocationHandler invokerHandler;
 
   static ComplexFactoryInvocationHandler getInstance(
-          final EntityContainerInvocationHandler containerHandler,
+          final Service<?> service,
           final EntityInvocationHandler entityHandler,
           final AbstractStructuredInvocationHandler targetHandler) {
 
-    return new ComplexFactoryInvocationHandler(containerHandler, entityHandler, targetHandler);
+    return new ComplexFactoryInvocationHandler(service, entityHandler, targetHandler);
   }
 
   static ComplexFactoryInvocationHandler getInstance(
@@ -49,18 +50,18 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
             targetHandler == null
             ? entityHandler == null
             ? null
-            : entityHandler.containerHandler
-            : targetHandler.containerHandler,
+            : entityHandler.service
+            : targetHandler.service,
             entityHandler,
             targetHandler);
   }
 
   private ComplexFactoryInvocationHandler(
-          final EntityContainerInvocationHandler containerHandler,
+          final Service<?> service,
           final EntityInvocationHandler entityHandler,
           final AbstractStructuredInvocationHandler targetHandler) {
 
-    super(containerHandler);
+    super(service);
     this.invokerHandler = targetHandler;
     this.entityHandler = entityHandler;
   }
@@ -81,9 +82,9 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
               new Class<?>[] {method.getReturnType()},
               entityHandler == null
               ? ComplexInvocationHandler.getInstance(
-                      getClient(), property.name(), method.getReturnType(), containerHandler)
+              getClient(), property.name(), method.getReturnType(), service)
               : ComplexInvocationHandler.getInstance(
-                      getClient(), property.name(), method.getReturnType(), entityHandler));
+              getClient(), property.name(), method.getReturnType(), entityHandler));
     } else {
       throw new NoSuchMethodException(method.getName());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
index 8d1c827..ba3108e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
@@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.domain.ODataLinked;
 import org.apache.olingo.commons.api.edm.EdmElement;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.ext.proxy.Service;
 import org.apache.olingo.ext.proxy.api.annotations.ComplexType;
 import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
 import org.apache.olingo.ext.proxy.api.annotations.Property;
@@ -83,10 +84,10 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
           final CommonEdmEnabledODataClient<?> client,
           final String propertyName,
           final Class<?> reference,
-          final EntityContainerInvocationHandler containerHandler) {
+          final Service<?> service) {
 
     final Pair<ODataComplexValue<? extends CommonODataProperty>, Class<?>> init = init(client, reference);
-    return new ComplexInvocationHandler(client, init.getLeft(), init.getRight(), containerHandler);
+    return new ComplexInvocationHandler(client, init.getLeft(), init.getRight(), service);
   }
 
   public static ComplexInvocationHandler getInstance(
@@ -113,12 +114,29 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
           final CommonEdmEnabledODataClient<?> client,
           final ODataComplexValue<?> complex,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler containerHandler) {
+          final Service<?> service) {
 
-    super(typeRef, complex, containerHandler);
+    super(typeRef, complex, service);
     this.client = client;
   }
 
+  public static ComplexInvocationHandler getInstance(
+          final Class<?> typeRef,
+          final Service<?> service) {
+    final Pair<ODataComplexValue<? extends CommonODataProperty>, Class<?>> init = init(service.getClient(), typeRef);
+    return new ComplexInvocationHandler(init.getLeft(), init.getRight(), service);
+  }
+
+  private ComplexInvocationHandler(
+          final ODataComplexValue<?> complex,
+          final Class<?> typeRef,
+          final Service<?> service) {
+
+    super(typeRef, service);
+    this.internal = complex;
+    this.client = service.getClient();
+  }
+
   @SuppressWarnings("unchecked")
   public ODataComplexValue<CommonODataProperty> getComplex() {
     return (ODataComplexValue<CommonODataProperty>) this.internal;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
index d57aab3..6182dd3 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
@@ -22,7 +22,7 @@ import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
 import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
+import org.apache.olingo.ext.proxy.api.EntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractTerm;
 import org.apache.olingo.ext.proxy.api.StructuredType;
 import org.apache.olingo.ext.proxy.api.annotations.Namespace;
@@ -38,10 +38,11 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import org.apache.olingo.ext.proxy.Service;
 
 public class EntityCollectionInvocationHandler<T extends StructuredType>
-        extends AbstractEntityCollectionInvocationHandler<T, AbstractEntityCollection<T>>
-        implements AbstractEntityCollection<T> {
+        extends AbstractEntityCollectionInvocationHandler<T, EntityCollection<T>>
+        implements EntityCollection<T> {
 
   private static final long serialVersionUID = 98078202642671726L;
 
@@ -54,16 +55,15 @@ public class EntityCollectionInvocationHandler<T extends StructuredType>
   private final Map<Class<? extends AbstractTerm>, Object> annotationsByTerm =
           new HashMap<Class<? extends AbstractTerm>, Object>();
 
-  public EntityCollectionInvocationHandler(final EntityContainerInvocationHandler containerHandler,
-          final Collection<T> items, final Class<T> itemRef) {
-
-    this(containerHandler, items, itemRef, null);
+  public EntityCollectionInvocationHandler(
+          final Service<?> service, final Collection<T> items, final Class<T> itemRef) {
+    this(service, items, itemRef, null);
   }
 
-  public EntityCollectionInvocationHandler(final EntityContainerInvocationHandler containerHandler,
-          final Collection<T> items, final Class<T> itemRef, final CommonURIBuilder<?> uri) {
+  public EntityCollectionInvocationHandler(
+          final Service<?> service, final Collection<T> items, final Class<T> itemRef, final CommonURIBuilder<?> uri) {
 
-    super(itemRef, null, containerHandler, uri);
+    super(itemRef, null, service, uri);
     this.items = items;
   }
 
@@ -119,7 +119,7 @@ public class EntityCollectionInvocationHandler<T extends StructuredType>
   }
 
   @SuppressWarnings("unchecked")
-  public AbstractEntityCollection<T> execute() {
+  public EntityCollection<T> execute() {
     final Triple<List<T>, URI, List<ODataAnnotation>> entitySet = fetchPartialEntitySet(this.uri.build(), itemRef);
     this.nextPageURI = entitySet.getMiddle();
 
@@ -168,6 +168,11 @@ public class EntityCollectionInvocationHandler<T extends StructuredType>
 
   @Override
   public boolean add(final T element) {
+    final EntityInvocationHandler handler = EntityInvocationHandler.class.cast(Proxy.getInvocationHandler(element));
+    if (!service.getContext().entityContext().isAttached(handler) && baseURI != null) {
+      handler.updateUUID(baseURI, itemRef, null);
+      service.getContext().entityContext().attachNew(handler);
+    }
     return items.add(element);
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index 14b313c..a892081 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@ -39,11 +39,9 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
 
   private final boolean defaultEC;
 
-  public static EntityContainerInvocationHandler getInstance(
-          final Class<?> ref, final Service<?> factory) {
+  public static EntityContainerInvocationHandler getInstance(final Class<?> ref, final Service<?> service) {
 
-    final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(ref, factory);
-    instance.containerHandler = instance;
+    final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(ref, service);
     return instance;
   }
 
@@ -61,8 +59,8 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
     this.namespace = ((EntityContainer) annotation).namespace();
   }
 
-  protected Service<?> getFactory() {
-    return factory;
+  protected Service<?> getService() {
+    return service;
   }
 
   protected boolean isDefaultEntityContainer() {
@@ -82,7 +80,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
     if (isSelfMethod(method, args)) {
       return invokeSelfMethod(method, args);
     } else if ("flush".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
-      factory.getPersistenceManager().flush();
+      service.getPersistenceManager().flush();
       return ClassUtils.returnVoid();
     } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
       final Class<?> returnType = method.getReturnType();
@@ -97,7 +95,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
       return Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {returnType},
-              ComplexFactoryInvocationHandler.getInstance(this, null, null));
+              ComplexFactoryInvocationHandler.getInstance(service, null, null));
     } else {
       final Class<?> returnType = method.getReturnType();
 
@@ -108,13 +106,13 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
           return Proxy.newProxyInstance(
                   Thread.currentThread().getContextClassLoader(),
                   new Class<?>[] {returnType},
-                  SingletonInvocationHandler.getInstance(returnType, this, singleton.name()));
+                  SingletonInvocationHandler.getInstance(returnType, service, singleton.name()));
         }
       } else {
         return Proxy.newProxyInstance(
                 Thread.currentThread().getContextClassLoader(),
                 new Class<?>[] {returnType},
-                EntitySetInvocationHandler.getInstance(returnType, this, entitySet.name()));
+                EntitySetInvocationHandler.getInstance(returnType, service, entitySet.name()));
       }
 
       throw new NoSuchMethodException(method.getName());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
index fbff500..c29e6ea 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
@@ -30,8 +30,10 @@ import org.apache.olingo.commons.api.domain.CommonODataProperty;
 import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
 import org.apache.olingo.commons.api.domain.v4.ODataEntity;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.ext.proxy.Service;
 import org.apache.olingo.ext.proxy.api.AbstractTerm;
 import org.apache.olingo.ext.proxy.api.Annotatable;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
@@ -68,8 +70,6 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
 
   private URI baseURI;
 
-  private CommonURIBuilder<?> uri;
-
   protected final Map<String, Object> propertyChanges = new HashMap<String, Object>();
 
   protected final Map<NavigationProperty, Object> linkChanges = new HashMap<NavigationProperty, Object>();
@@ -97,7 +97,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
             entity,
             entitySet.getURI(),
             typeRef,
-            entitySet.containerHandler);
+            entitySet.service);
   }
 
   static EntityInvocationHandler getInstance(
@@ -105,18 +105,75 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
           final CommonODataEntity entity,
           final URI entitySetURI,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler containerHandler) {
+          final Service<?> service) {
+
+    return new EntityInvocationHandler(key, entity, entitySetURI, typeRef, service);
+  }
+
+  public static EntityInvocationHandler getInstance(
+          final CommonODataEntity entity,
+          final URI entitySetURI,
+          final Class<?> typeRef,
+          final Service<?> service) {
 
-    return new EntityInvocationHandler(key, entity, entitySetURI, typeRef, containerHandler);
+    return new EntityInvocationHandler(null, entity, entitySetURI, typeRef, service);
   }
 
   public static EntityInvocationHandler getInstance(
           final CommonODataEntity entity,
           final URI entitySetURI,
+          final URI entityURI,
+          final Class<?> typeRef,
+          final Service<?> service) {
+
+    return new EntityInvocationHandler(entity, entityURI, entitySetURI, typeRef, service);
+  }
+
+  public static EntityInvocationHandler getInstance(
+          final Class<?> typeRef,
+          final Service<?> service) {
+
+    return new EntityInvocationHandler(typeRef, service);
+  }
+
+  private EntityInvocationHandler(
+          final Class<?> typeRef,
+          final Service<?> service) {
+
+    super(typeRef, service);
+
+    final String name = typeRef.getAnnotation(org.apache.olingo.ext.proxy.api.annotations.EntityType.class).name();
+    final String namespace = typeRef.getAnnotation(Namespace.class).value();
+
+    this.internal = service.getClient().getObjectFactory().newEntity(new FullQualifiedName(namespace, name));
+    CommonODataEntity.class.cast(this.internal).setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream());
+
+    this.uuid = new EntityUUID(
+            null,
+            typeRef,
+            null);
+  }
+
+  private EntityInvocationHandler(
+          final CommonODataEntity entity,
+          final URI entitySetURI,
+          final URI entityURI,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler containerHandler) {
+          final Service<?> service) {
+    super(typeRef, entity, service);
 
-    return new EntityInvocationHandler(null, entity, entitySetURI, typeRef, containerHandler);
+    if (entityURI != null) {
+      this.baseURI = entityURI;
+      this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
+    } else {
+      this.baseURI = null;
+      this.uri = null;
+    }
+
+    this.internal = entity;
+    getEntity().setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream());
+
+    this.uuid = new EntityUUID(entitySetURI, typeRef, null);
   }
 
   private EntityInvocationHandler(
@@ -124,12 +181,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
           final CommonODataEntity entity,
           final URI entitySetURI,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler containerHandler) {
+          final Service<?> service) {
+
+    super(typeRef, entity, service);
 
-    super(typeRef, entity, containerHandler);
-    
     final Object key = entityKey == null ? CoreUtils.getKey(getClient(), this, typeRef, entity) : entityKey;
-    
+
     if (entity.getEditLink() != null) {
       this.baseURI = entity.getEditLink();
       this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
@@ -155,11 +212,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
     this.internal = entity;
     getEntity().setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream());
 
-    this.uuid = new EntityUUID(
-            containerHandler.getEntityContainerName(),
-            entitySetURI,
-            typeRef,
-            key);
+    this.uuid = new EntityUUID(entitySetURI, typeRef, key);
   }
 
   public void setEntity(final CommonODataEntity entity) {
@@ -167,7 +220,6 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
     getEntity().setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream());
 
     this.uuid = new EntityUUID(
-            getUUID().getContainerName(),
             getUUID().getEntitySetURI(),
             getUUID().getType(),
             CoreUtils.getKey(getClient(), this, typeRef, entity));
@@ -190,8 +242,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
     return uuid;
   }
 
-  public String getEntityContainerName() {
-    return uuid.getContainerName();
+  public EntityUUID updateUUID(final URI entitySetURI, final Class<?> type, final Object key) {
+    this.uuid = new EntityUUID(entitySetURI, type, key);
+    return this.uuid;
   }
 
   public URI getEntitySetURI() {
@@ -539,9 +592,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
       setEntity(entity);
       setETag(etag);
 
-      if (!key.equals(CoreUtils.getKey(getClient(), this, typeRef, entity))) {
+      if (key != null && !key.equals(CoreUtils.getKey(getClient(), this, typeRef, entity))) {
         throw new IllegalArgumentException("Invalid " + typeRef.getSimpleName() + "(" + key + ")");
       }
+
+      IOUtils.closeQuietly(this.stream);
+      this.stream = null;
     } catch (IllegalArgumentException e) {
       LOG.warn("Entity '" + uuid + "' not found", e);
       throw e;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
index 888ff38..cb87c1e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
@@ -18,7 +18,6 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
-import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
@@ -29,7 +28,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
+import org.apache.olingo.ext.proxy.api.EntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
 import org.apache.olingo.ext.proxy.api.AbstractSingleton;
 import org.apache.olingo.ext.proxy.api.Search;
@@ -44,14 +43,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.ext.proxy.Service;
+import org.apache.olingo.ext.proxy.api.annotations.Namespace;
+import org.apache.olingo.ext.proxy.api.annotations.Singleton;
 
 class EntitySetInvocationHandler<
-        T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+        T extends StructuredType, KEY extends Serializable, EC extends EntityCollection<T>>
         extends AbstractEntityCollectionInvocationHandler<T, EC>
         implements AbstractEntitySet<T, KEY, EC> {
 
@@ -62,74 +68,78 @@ class EntitySetInvocationHandler<
    */
   private static final Logger LOG = LoggerFactory.getLogger(EntitySetInvocationHandler.class);
 
-  @SuppressWarnings("unchecked")
-  static EntitySetInvocationHandler getInstance(
-          final Class<?> itemRef,
-          final Class<?> collItemRef,
-          final EntityContainerInvocationHandler containerHandler,
-          final String entitySetName) {
-
-    final CommonURIBuilder<?> uriBuilder = buildURI(containerHandler, entitySetName);
-
-    uriBuilder.appendDerivedEntityTypeSegment(new FullQualifiedName(
-            ClassUtils.getNamespace(itemRef), ClassUtils.getEntityTypeName(itemRef)).toString());
-
-    return new EntitySetInvocationHandler(itemRef, collItemRef, containerHandler, entitySetName, uriBuilder);
-  }
-
   @SuppressWarnings({"rawtypes", "unchecked"})
   static EntitySetInvocationHandler getInstance(
           final Class<?> ref,
-          final EntityContainerInvocationHandler containerHandler,
+          final Service<?> service,
           final String entitySetName) {
 
-    return new EntitySetInvocationHandler(
-            ref, containerHandler, entitySetName, buildURI(containerHandler, entitySetName));
+    return new EntitySetInvocationHandler(ref, service, entitySetName, buildURI(ref, service, entitySetName));
   }
 
   @SuppressWarnings({"rawtypes", "unchecked"})
   static EntitySetInvocationHandler getInstance(
-          final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final URI uri) {;
+          final Class<?> ref, final Service<?> service, final URI uri) {;
 
-    return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name(),
-            containerHandler.getClient().newURIBuilder(uri.toASCIIString()));
+    return new EntitySetInvocationHandler(
+            ref,
+            service,
+            (ref.getAnnotation(EntitySet.class)).name(),
+            service.getClient().newURIBuilder(uri.toASCIIString()));
   }
 
   private static CommonURIBuilder<?> buildURI(
-          final EntityContainerInvocationHandler containerHandler,
+          final Class<?> ref,
+          final Service<?> service,
           final String entitySetName) {
-    final CommonURIBuilder<?> uriBuilder = containerHandler.getClient().newURIBuilder();
+    final CommonURIBuilder<?> uriBuilder = service.getClient().newURIBuilder();
+
+    final Edm edm = service.getClient().getCachedEdm();
+    final String containerNS;
+    Annotation ann = ref.getAnnotation(EntitySet.class);
+    if (ann instanceof EntitySet) {
+      containerNS = EntitySet.class.cast(ann).container();
+    } else {
+      ann = ref.getAnnotation(Singleton.class);
+      if (ann instanceof Singleton) {
+        containerNS = Singleton.class.cast(ann).container();
+      } else {
+        containerNS = null;
+      }
+    }
 
     final StringBuilder entitySetSegment = new StringBuilder();
-    if (!containerHandler.isDefaultEntityContainer()) {
-      entitySetSegment.append(containerHandler.getEntityContainerName()).append('.');
+    if (StringUtils.isNotBlank(containerNS)) {
+      final EdmEntityContainer container = edm.getEntityContainer(new FullQualifiedName(containerNS));
+      if (!container.isDefault()) {
+        entitySetSegment.append(container.getFullQualifiedName().toString()).append('.');
+      }
     }
-    entitySetSegment.append(entitySetName);
 
+    entitySetSegment.append(entitySetName);
     uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
-
     return uriBuilder;
   }
 
   @SuppressWarnings("unchecked")
   protected EntitySetInvocationHandler(
           final Class<?> ref,
-          final EntityContainerInvocationHandler containerHandler,
+          final Service<?> service,
           final String entitySetName,
           final CommonURIBuilder<?> uri) {
 
-    super(ref, containerHandler, uri);
+    super(ref, service, uri);
   }
 
   @SuppressWarnings("unchecked")
   protected EntitySetInvocationHandler(
           final Class<?> itemRef,
           final Class<EC> collItemRef,
-          final EntityContainerInvocationHandler containerHandler,
+          final Service<?> service,
           final String entitySetName,
           final CommonURIBuilder<?> uri) {
 
-    super(itemRef, collItemRef, containerHandler, uri);
+    super(itemRef, collItemRef, service, uri);
   }
 
   @Override
@@ -144,38 +154,18 @@ class EntitySetInvocationHandler<
       return proxy;
     } else if (isSelfMethod(method, args)) {
       return invokeSelfMethod(method, args);
-    } else if (method.getName().startsWith("new") && ArrayUtils.isEmpty(args)) {
-      if (method.getName().endsWith("Collection")) {
-        return newEntityCollection(method.getReturnType());
-      } else {
-        return newEntity(method.getReturnType());
-      }
     } else {
       throw new NoSuchMethodException(method.getName());
     }
   }
 
-  @SuppressWarnings("unchecked")
-  private <NE> NE newEntity(final Class<NE> reference) {
-    final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
-            new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(reference)));
-
-    final EntityInvocationHandler handler =
-            EntityInvocationHandler.getInstance(entity, this.baseURI, reference, containerHandler);
-    getContext().entityContext().attachNew(handler);
-
-    return (NE) Proxy.newProxyInstance(
-            Thread.currentThread().getContextClassLoader(),
-            new Class<?>[] {reference},
-            handler);
-  }
-
-  @SuppressWarnings("unchecked")
-  private <NEC> NEC newEntityCollection(final Class<NEC> reference) {
-    return (NEC) Proxy.newProxyInstance(
-            Thread.currentThread().getContextClassLoader(),
-            new Class<?>[] {reference},
-            new EntityCollectionInvocationHandler<T>(containerHandler, new ArrayList<T>(), itemRef));
+  @Override
+  public void add(final T entity) {
+    final EntityInvocationHandler handler = EntityInvocationHandler.class.cast(Proxy.getInvocationHandler(entity));
+    if (!getContext().entityContext().isAttached(handler)) {
+      handler.updateUUID(baseURI, itemRef, null);
+      getContext().entityContext().attachNew(handler);
+    }
   }
 
   @Override
@@ -209,16 +199,16 @@ class EntitySetInvocationHandler<
       throw new IllegalArgumentException("Null key");
     }
 
-    final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), this.baseURI, typeRef, key);
+    final EntityUUID uuid = new EntityUUID(this.baseURI, typeRef, key);
     LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
 
     EntityInvocationHandler handler = getContext().entityContext().getEntity(uuid);
 
     if (handler == null) {
-      final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
-              new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(typeRef)));
+      final CommonODataEntity entity = getClient().getObjectFactory().newEntity(new FullQualifiedName(
+              typeRef.getAnnotation(Namespace.class).value(), ClassUtils.getEntityTypeName(typeRef)));
 
-      handler = EntityInvocationHandler.getInstance(key, entity, this.baseURI, typeRef, containerHandler);
+      handler = EntityInvocationHandler.getInstance(key, entity, this.baseURI, typeRef, service);
 
     } else if (isDeleted(handler)) {
       // object deleted
@@ -237,11 +227,11 @@ class EntitySetInvocationHandler<
   }
 
   @SuppressWarnings("unchecked")
-  public <S extends T, SEC extends AbstractEntityCollection<S>> SEC execute(final Class<SEC> collTypeRef) {
+  public <S extends T, SEC extends EntityCollection<S>> SEC execute(final Class<SEC> collTypeRef) {
     final Class<S> ref = (Class<S>) ClassUtils.extractTypeArg(collTypeRef,
-            AbstractEntitySet.class, AbstractSingleton.class, AbstractEntityCollection.class);
+            AbstractEntitySet.class, AbstractSingleton.class, EntityCollection.class);
     final Class<S> oref = (Class<S>) ClassUtils.extractTypeArg(this.collItemRef,
-            AbstractEntitySet.class, AbstractSingleton.class, AbstractEntityCollection.class);
+            AbstractEntitySet.class, AbstractSingleton.class, EntityCollection.class);
 
     final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.uri.build().toASCIIString());
 
@@ -256,7 +246,7 @@ class EntitySetInvocationHandler<
     annotations.addAll(entitySet.getRight());
 
     final EntityCollectionInvocationHandler<S> entityCollectionHandler =
-            new EntityCollectionInvocationHandler<S>(containerHandler, entitySet.getLeft(), ref, uriBuilder);
+            new EntityCollectionInvocationHandler<S>(service, entitySet.getLeft(), ref, uriBuilder);
     entityCollectionHandler.setAnnotations(annotations);
 
     entityCollectionHandler.setNextPage(entitySet.getMiddle());
@@ -277,7 +267,7 @@ class EntitySetInvocationHandler<
 
   @Override
   @SuppressWarnings("unchecked")
-  public <S extends T, SEC extends AbstractEntityCollection<S>> Search<S, SEC> createSearch(
+  public <S extends T, SEC extends EntityCollection<S>> Search<S, SEC> createSearch(
           final Class<SEC> reference) {
 
     if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
@@ -294,11 +284,7 @@ class EntitySetInvocationHandler<
   public void delete(final KEY key) throws IllegalArgumentException {
     final EntityContext entityContext = getContext().entityContext();
 
-    EntityInvocationHandler entity = entityContext.getEntity(new EntityUUID(
-            containerHandler.getEntityContainerName(),
-            baseURI,
-            itemRef,
-            key));
+    EntityInvocationHandler entity = entityContext.getEntity(new EntityUUID(baseURI, itemRef, key));
 
     if (entity == null) {
       // search for entity

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
index 5534c93..60c0068 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
@@ -18,11 +18,6 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
-import org.apache.commons.lang3.tuple.Triple;
-import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
-import org.apache.olingo.ext.proxy.api.StructuredType;
-
 import java.io.Serializable;
 import java.net.URI;
 import java.util.Collections;
@@ -30,7 +25,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
 
-class EntitySetIterator<T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
+import org.apache.olingo.ext.proxy.api.EntityCollection;
+import org.apache.olingo.ext.proxy.api.StructuredType;
+
+class EntitySetIterator<T extends StructuredType, KEY extends Serializable, EC extends EntityCollection<T>>
         implements Iterator<T> {
 
   private final EntitySetInvocationHandler<T, KEY, EC> esi;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
index 9bf1468..1757397 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
@@ -18,15 +18,19 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.olingo.client.api.communication.request.ODataBasicRequest;
 import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
+import org.apache.olingo.client.api.communication.request.ODataRequest;
 import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
 import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
 import org.apache.olingo.client.api.communication.response.ODataResponse;
+import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
 import org.apache.olingo.ext.proxy.Service;
 
-import java.util.Map;
-
 /**
  * {@link org.apache.olingo.ext.proxy.api.PersistenceManager} implementation not using OData batch requests: any
  * read-write operation will be sent separately to the OData service when calling <tt>flush()</tt>; any intermediate
@@ -42,16 +46,41 @@ public class NonTransactionalPersistenceManagerImpl extends AbstractPersistenceM
 
   @Override
   protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
+    final Map<Integer, URI> responses = new HashMap<Integer, URI>();
+    int virtualContentID = 0;
+
     for (Map.Entry<ODataBatchableRequest, EntityInvocationHandler> entry : changes.getChanges().entrySet()) {
+      virtualContentID++;
+
       try {
-        final ODataResponse response = ((ODataBasicRequest<?>) entry.getKey()).execute();
+        final ODataRequest req = ODataRequest.class.cast(entry.getKey());
+        String uri = req.getURI().toASCIIString();
+        if (uri.startsWith("$")) {
+          int slashIndex = uri.indexOf('/');
+          final Integer toBeReplaced = Integer.valueOf(uri.substring(1, slashIndex < 0 ? uri.length() : slashIndex));
+          if (responses.containsKey(toBeReplaced)) {
+            uri = uri.replace("$" + toBeReplaced, responses.get(Integer.valueOf(toBeReplaced)).toASCIIString());
+            req.setURI(URI.create(uri));
+          }
+        }
+
+        final ODataResponse response;
+        if (ODataStreamedRequest.class.isAssignableFrom(req.getClass())) {
+          response = ((ODataStreamedRequest<?, ?>) req).payloadManager().getResponse();
+        } else {
+          response = ((ODataBasicRequest<?>) req).execute();
+        }
 
         if (response instanceof ODataEntityCreateResponse && response.getStatusCode() == 201) {
           entry.getValue().setEntity(((ODataEntityCreateResponse<?>) response).getBody());
+          responses.put(virtualContentID, entry.getValue().getEntityURI());
           LOG.debug("Upgrade created object '{}'", entry.getValue());
         } else if (response instanceof ODataEntityUpdateResponse && response.getStatusCode() == 200) {
           entry.getValue().setEntity(((ODataEntityUpdateResponse<?>) response).getBody());
+          responses.put(virtualContentID, entry.getValue().getEntityURI());
           LOG.debug("Upgrade updated object '{}'", entry.getValue());
+        } else {
+          responses.put(virtualContentID, null);
         }
       } catch (Exception e) {
         LOG.error("While performing {}", entry.getKey().getURI(), e);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
index a0ddf29..8c9a01d 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
@@ -64,21 +64,21 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme
   }
 
   private OperationInvocationHandler(final EntityContainerInvocationHandler containerHandler) {
-    super(containerHandler);
+    super(containerHandler.service);
 
     this.target = containerHandler;
     this.targetFQN = new FullQualifiedName(containerHandler.getSchemaName(), containerHandler.getEntityContainerName());
   }
 
   private OperationInvocationHandler(final EntityInvocationHandler entityHandler) {
-    super(entityHandler.containerHandler);
+    super(entityHandler.service);
 
     this.target = entityHandler;
     this.targetFQN = entityHandler.getEntity().getTypeName();
   }
 
   private OperationInvocationHandler(final EntityCollectionInvocationHandler<?> collectionHandler) {
-    super(collectionHandler.containerHandler);
+    super(collectionHandler.service);
 
     this.target = collectionHandler;
 
@@ -156,7 +156,7 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme
   }
 
   private Map.Entry<URI, EdmOperation> getBoundOperation(final Operation operation, final List<String> parameterNames) {
-    final CommonODataEntity entity = ((EntityInvocationHandler) target).getEntity();
+    final CommonODataEntity entity = EntityInvocationHandler.class.cast(target).getEntity();
 
     ODataOperation boundOp = entity.getOperation(operation.name());
     if (boundOp == null) {
@@ -196,7 +196,8 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme
         boundOp = new ODataOperation();
         boundOp.setMetadataAnchor(func.getFullQualifiedName().toString());
         boundOp.setTitle(boundOp.getMetadataAnchor());
-        boundOp.setTarget(URI.create(entity.getEditLink().toString() + "/"
+        boundOp.setTarget(URI.create((entity.getEditLink() == null
+                ? EntityInvocationHandler.class.cast(target).getEntityURI() : entity.getEditLink()).toString() + "/"
                 + (useOperationFQN ? func.getFullQualifiedName().toString() : operation.name())));
       } else {
         baseType = baseType.getBaseType();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
index 129fe47..e2787f7 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
@@ -18,19 +18,18 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
+import java.net.URI;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.olingo.client.api.uri.v4.URIBuilder;
 import org.apache.olingo.client.api.uri.v4.URISearch;
 import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
+import org.apache.olingo.ext.proxy.api.EntityCollection;
 import org.apache.olingo.ext.proxy.api.Search;
 import org.apache.olingo.ext.proxy.api.StructuredType;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 
-import java.net.URI;
-
-public class SearchImpl<T extends StructuredType, EC extends AbstractEntityCollection<T>> implements Search<T, EC> {
+public class SearchImpl<T extends StructuredType, EC extends EntityCollection<T>> implements Search<T, EC> {
 
   private static final long serialVersionUID = 4383858176507769973L;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
index fbd4833..41a416e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
@@ -18,14 +18,14 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
-import org.apache.olingo.ext.proxy.api.AbstractSingleton;
-
 import java.io.Serializable;
 import java.lang.reflect.Method;
+import org.apache.olingo.ext.proxy.Service;
+import org.apache.olingo.ext.proxy.api.EntityCollection;
+import org.apache.olingo.ext.proxy.api.AbstractSingleton;
 
 public class SingletonInvocationHandler<
-        T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+        T extends Serializable, KEY extends Serializable, EC extends EntityCollection<T>>
         extends AbstractInvocationHandler
         implements AbstractSingleton<T, KEY, EC> {
 
@@ -33,18 +33,17 @@ public class SingletonInvocationHandler<
 
   @SuppressWarnings({"rawtypes", "unchecked"})
   static SingletonInvocationHandler getInstance(
-          final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final String singletonName) {
+          final Class<?> ref, final Service<?> service, final String singletonName) {
 
-    return new SingletonInvocationHandler(ref, containerHandler, singletonName);
+    return new SingletonInvocationHandler(ref, service, singletonName);
   }
   private final EntitySetInvocationHandler<?, ?, ?> entitySetHandler;
 
   @SuppressWarnings({"rawtypes", "unchecked"})
-  private SingletonInvocationHandler(
-          final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final String singletonName) {
+  private SingletonInvocationHandler(final Class<?> ref, final Service<?> service, final String singletonName) {
 
-    super(containerHandler);
-    this.entitySetHandler = EntitySetInvocationHandler.getInstance(ref, containerHandler, singletonName);
+    super(service);
+    this.entitySetHandler = EntitySetInvocationHandler.getInstance(ref, service, singletonName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
index 3da3019..80807ad 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
@@ -54,9 +54,9 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
   @Override
   protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
     final CommonODataBatchRequest request =
-            factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot());
+            service.getClient().getBatchRequestFactory().getBatchRequest(service.getClient().getServiceRoot());
     ((ODataRequest) request).setAccept(
-            factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
+            service.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
 
     final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
index ed39aec..c2aaaa5 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
@@ -89,10 +89,12 @@ public class EntityContext implements Iterable<AttachedEntity> {
       throw new IllegalStateException("An entity with the same profile has already been attached");
     }
 
-    allAttachedEntities.put(entity, status);
+    if (entity.getUUID().getEntitySetURI() != null) {
+      allAttachedEntities.put(entity, status);
 
-    if (entity.getUUID().getKey() != null) {
-      searchableEntities.put(entity.getUUID(), entity);
+      if (entity.getUUID().getKey() != null) {
+        searchableEntities.put(entity.getUUID(), entity);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
index 822e01d..b825c99 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
@@ -24,17 +24,15 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
-import org.apache.olingo.ext.proxy.api.StructuredType;
 
 import java.io.Serializable;
 import java.net.URI;
+import org.apache.olingo.ext.proxy.api.EntityType;
 
 public class EntityUUID implements Serializable {
 
   private static final long serialVersionUID = 4855025769803086495L;
 
-  private final String containerName;
-
   private final URI entitySetURI;
 
   private final Object key;
@@ -46,12 +44,11 @@ public class EntityUUID implements Serializable {
 
   private Class<?> type;
 
-  public EntityUUID(final String containerName, final URI entitySetURI, final Class<?> type) {
-    this(containerName, entitySetURI, type, null);
+  public EntityUUID(final URI entitySetURI, final Class<?> type) {
+    this(entitySetURI, type, null);
   }
 
-  public EntityUUID(final String containerName, final URI entitySetURI, final Class<?> type, final Object key) {
-    this.containerName = containerName;
+  public EntityUUID(final URI entitySetURI, final Class<?> type, final Object key) {
     this.entitySetURI = entitySetURI;
     this.key = key;
     this.tempKey = (int) (Math.random() * 1000000);
@@ -63,17 +60,13 @@ public class EntityUUID implements Serializable {
       if (this.type == null
               && (clazz.getInterfaces().length == 0
               || ArrayUtils.contains(clazz.getInterfaces(), Serializable.class)
-              || ArrayUtils.contains(clazz.getInterfaces(), StructuredType.class))) {
+              || ArrayUtils.contains(clazz.getInterfaces(), EntityType.class))) {
 
         this.type = clazz;
       }
     }
   }
 
-  public String getContainerName() {
-    return containerName;
-  }
-
   public URI getEntitySetURI() {
     return entitySetURI;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index 0e33398..c9effa9 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -70,6 +70,10 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
 
 public final class CoreUtils {
 
@@ -656,4 +660,26 @@ public final class CoreUtils {
 
     throw new IllegalArgumentException("Invalid streamed property " + name);
   }
+
+  public static URI getTargetEntitySetURI(
+          final CommonEdmEnabledODataClient<?> client, final NavigationProperty property) {
+    final Edm edm = client.getCachedEdm();
+
+    final FullQualifiedName containerName =
+            new FullQualifiedName(property.targetSchema(), property.targetContainer());
+
+    final EdmEntityContainer container = edm.getEntityContainer(containerName);
+    final CommonURIBuilder<?> uriBuilder = client.newURIBuilder(client.getServiceRoot());
+
+    if (!container.isDefault()) {
+      final StringBuilder entitySetSegment = new StringBuilder();
+      entitySetSegment.append(container.getFullQualifiedName()).append('.');
+      entitySetSegment.append(property.targetEntitySet());
+      uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
+    } else {
+      uriBuilder.appendEntitySetSegment(property.targetEntitySet());
+    }
+
+    return uriBuilder.build();
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
index 572408e..f0b48b1 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
@@ -283,10 +283,7 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
           parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs);
         }
 
-        final List<EdmEntityType> entities = new ArrayList<EdmEntityType>();
-
         for (EdmEntityType entity : schema.getEntityTypes()) {
-          entities.add(entity);
           objs.clear();
           objs.put("entityType", entity);
 
@@ -330,35 +327,24 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
           objs.put("namespace", schema.getNamespace());
           objs.put("complexes", complexes);
 
-          parseObj(base, pkg, "container",
-                  utility.capitalize(container.getName()) + ".java", objs);
+          parseObj(base, pkg, "container", utility.capitalize(container.getName()) + ".java", objs);
 
           for (EdmEntitySet entitySet : container.getEntitySets()) {
             objs.clear();
             objs.put("entitySet", entitySet);
-            parseObj(base, pkg, "entitySet",
-                    utility.capitalize(entitySet.getName()) + ".java", objs);
+            objs.put("container", container);
+            parseObj(base, pkg, "entitySet", utility.capitalize(entitySet.getName()) + ".java", objs);
           }
 
           if (ODataServiceVersion.valueOf(getVersion().toUpperCase()).compareTo(ODataServiceVersion.V40) >= 0) {
             for (EdmSingleton singleton : container.getSingletons()) {
               objs.clear();
               objs.put("singleton", singleton);
-              parseObj(base, pkg, "singleton",
-                      utility.capitalize(singleton.getName()) + ".java", objs);
+              objs.put("container", container);
+              parseObj(base, pkg, "singleton", utility.capitalize(singleton.getName()) + ".java", objs);
             }
           }
         }
-
-        objs.clear();
-        objs.put("namespace", schema.getNamespace());
-        objs.put("complexes", complexes);
-        parseObj(base, pkg, "complexCreator", "ComplexCreator.java", objs);
-
-        objs.clear();
-        objs.put("namespace", schema.getNamespace());
-        objs.put("entities", entities);
-        parseObj(base, pkg, "entityCreator", "EntityCreator.java", objs);
       }
 
       final File metaInf = mkdir("META-INF");

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
deleted file mode 100644
index af23884..0000000
--- a/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
+++ /dev/null
@@ -1,32 +0,0 @@
-#*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *#
-package ${package};
-
-import org.apache.olingo.ext.proxy.api.annotations.Namespace;
-import org.apache.olingo.ext.proxy.api.annotations.Property;
-
-@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
-public interface ComplexCreator {
-  #foreach($complex in $complexes)
-      #set( $type = "${namespace}.${complex.Name}" )
-      @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$complex.Name", type = "$type")
-      $utility.getJavaType($type) new$utility.capitalize($complex.Name)();
-
-  #end
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/complexType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm
index ee7c28d..a54938d 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/complexType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm
@@ -18,6 +18,7 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.annotations.AnnotationsForProperty;
 import org.apache.olingo.ext.proxy.api.annotations.AnnotationsForNavigationProperty;
 import org.apache.olingo.ext.proxy.api.annotations.Namespace;
@@ -30,7 +31,6 @@ import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
 import org.apache.olingo.ext.proxy.api.Annotatable;
 #foreach($ns in $namespaces)
 import #if($basePackage)${basePackage}.#end${ns}.*;
-import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
 import org.apache.olingo.commons.api.edm.geo.Geospatial;
@@ -41,6 +41,7 @@ import org.apache.olingo.commons.api.edm.geo.MultiPoint;
 import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
 import org.apache.olingo.commons.api.edm.geo.Point;
 import org.apache.olingo.commons.api.edm.geo.Polygon;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #parse( "${odataVersion}/complexType.vm" )
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/container.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/container.vm b/ext/pojogen-maven-plugin/src/main/resources/container.vm
index 87e89b0..ac2aab6 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/container.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/container.vm
@@ -19,6 +19,7 @@
 #set( $clsSuffix = ".class" )
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.client.api.http.HttpMethod;
 import org.apache.olingo.ext.proxy.api.annotations.Operation;
 import org.apache.olingo.ext.proxy.api.annotations.Parameter;
@@ -26,7 +27,6 @@ import org.apache.olingo.ext.proxy.api.annotations.Property;
 import org.apache.olingo.ext.proxy.api.PersistenceManager;
 import org.apache.olingo.ext.proxy.api.OperationType;
 #foreach($ns in $namespaces)
-import #if($basePackage)${basePackage}.#end${ns}.*;
 import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
@@ -45,6 +45,7 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.Calendar;
 import javax.xml.datatype.Duration;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 @org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
 @org.apache.olingo.ext.proxy.api.annotations.EntityContainer(name = "$container.Name",
@@ -102,19 +103,5 @@ public interface $utility.capitalize($container.Name) extends PersistenceManager
 
   #end
   #end
-  }
-
-  #if( $complexes.size() > 0 )
-    ComplexFactory complexFactory();
-
-    interface ComplexFactory {
-    #foreach($complex in $complexes)
-      #set( $type = "${namespace}.${complex.Name}" )
-      @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$complex.Name",
-                type = "$type")
-      $utility.getJavaType($type) new$utility.capitalize($complex.Name)();
-
-    #end
-    }
-  #end   
+  }   
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm
index 0f46ece..92ac748 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm
@@ -18,15 +18,14 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractTerm;
 import org.apache.olingo.ext.proxy.api.OperationType;
 import org.apache.olingo.ext.proxy.api.annotations.Operation;
 import org.apache.olingo.ext.proxy.api.annotations.Parameter;
 #foreach($ns in $namespaces)
 import #if($basePackage)${basePackage}.#end${ns}.*;
-import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
 import org.apache.olingo.commons.api.edm.geo.Geospatial;
@@ -44,11 +43,12 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.Calendar;
 import javax.xml.datatype.Duration;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #set ( $javaEntityType = $utility.getJavaType($entityType) )
 
 public interface $utility.capitalize($entityType.Name)Collection extends 
-    org.apache.olingo.ext.proxy.api.EntityCollectionQuery<$javaEntityType, ${javaEntityType}Collection, ${javaEntityType}Collection>, AbstractEntityCollection<$javaEntityType> {
+    org.apache.olingo.ext.proxy.api.EntityCollectionQuery<$javaEntityType, ${javaEntityType}Collection, ${javaEntityType}Collection>, org.apache.olingo.ext.proxy.api.EntityCollection<$javaEntityType> {
 #set( $functions = $utility.getFunctionsBoundTo($entityType.Name, true) )
 #set( $actions = $utility.getActionsBoundTo($entityType.Name, true) )
 #if( $functions.size() > 0 || $actions.size() > 0 )

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
deleted file mode 100644
index bbb4628..0000000
--- a/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
+++ /dev/null
@@ -1,37 +0,0 @@
-#*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *#
-package ${package};
-
-import org.apache.olingo.ext.proxy.api.annotations.Namespace;
-import org.apache.olingo.ext.proxy.api.annotations.Property;
-
-@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
-public interface EntityCreator {
-
-  #foreach($entity in $entities)
-  #set( $type = "${namespace}.${entity.Name}" )
-  #set( $javaType = $utility.getJavaType($type) )
-  @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
-  $javaType new$utility.capitalize($entity.Name)();
-
-  @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
-  ${javaType}Collection new${utility.capitalize($entity.Name)}Collection();
-
-  #end
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm
index f4fc556..4afefac 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm
@@ -18,12 +18,12 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
 import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement;
 #foreach($ns in $namespaces)
-import #if($basePackage)${basePackage}.#end${ns}.*;
 import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
@@ -42,6 +42,7 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.Calendar;
 import javax.xml.datatype.Duration;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #set( $keys = $utility.getEntityKeyType($entitySet) )
 #if( $keys.size() > 1 )
@@ -54,14 +55,7 @@ import javax.xml.datatype.Duration;
 
 #set ( $javaEntityType = $utility.getJavaType($entitySet.EntityType) )
 
-@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "$entitySet.Name")
+@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "$entitySet.Name", container = "$container.FullQualifiedName.toString()")
 public interface $utility.capitalize($entitySet.Name) 
   extends org.apache.olingo.ext.proxy.api.EntitySetQuery<$javaEntityType, ${javaEntityType}Collection, $utility.capitalize($entitySet.Name)>, AbstractEntitySet<$javaEntityType, $type, ${javaEntityType}Collection> {
-
-#foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($entitySet)) )
-    #set( $djt = $utility.getJavaType($dos) )
-    #set( $sIdx = $djt.lastIndexOf('.') + 1 )
-    $djt new$djt.substring($sIdx)();
-    ${djt}Collection new$djt.substring($sIdx)Collection();
-#end
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
index 65dac55..9289d39 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
@@ -18,7 +18,7 @@
  *#
 #set( $clsSuffix = ".class" )
 package ${package};
-
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.client.api.http.HttpMethod;
 import org.apache.olingo.ext.proxy.api.annotations.AnnotationsForProperty;
 import org.apache.olingo.ext.proxy.api.annotations.AnnotationsForNavigationProperty;
@@ -38,7 +38,6 @@ import org.apache.olingo.commons.api.edm.constants.EdmContentKind;
 import org.apache.olingo.client.api.edm.ConcurrencyMode;
 #foreach($ns in $namespaces)
 import #if($basePackage)${basePackage}.#end${ns}.*;
-import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
 import org.apache.olingo.commons.api.edm.geo.Geospatial;
@@ -49,6 +48,7 @@ import org.apache.olingo.commons.api.edm.geo.MultiPoint;
 import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
 import org.apache.olingo.commons.api.edm.geo.Point;
 import org.apache.olingo.commons.api.edm.geo.Polygon;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #if( $keyRef )@KeyRef(${keyRef}.class)#end
 
@@ -59,7 +59,7 @@ import org.apache.olingo.commons.api.edm.geo.Polygon;
         isAbstract = $entityType.Abstract#if($entityType.getBaseType()),
         baseType = "$entityType.getBaseType().getFullQualifiedName().toString()"#end)
 public interface $utility.capitalize($entityType.Name) 
-  extends org.apache.olingo.ext.proxy.api.StructuredType,org.apache.olingo.ext.proxy.api.Annotatable,#if( $entityType.getBaseType() )$utility.getJavaType($entityType.getBaseType())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($entityType.Name)>#end#{if}( $entityType.isOpenType() ),AbstractOpenType#end {
+  extends org.apache.olingo.ext.proxy.api.EntityType,org.apache.olingo.ext.proxy.api.Annotatable,#if( $entityType.getBaseType() )$utility.getJavaType($entityType.getBaseType())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($entityType.Name)>#end#{if}( $entityType.isOpenType() ),AbstractOpenType#end {
 
 #if( $entityType.getBaseType() )
   @Override
@@ -183,18 +183,6 @@ public interface $utility.capitalize($entityType.Name)
     }
 #end
 
-    ComplexFactory factory();
-
-    interface ComplexFactory #if( $entityType.baseType )
-           extends ${utility.getJavaType($entityType.getBaseType())}.ComplexFactory#end{
-#foreach($property in $complexProps)
-         @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$property.Name",
-                   type = "$property.Type.FullQualifiedName.toString()")
-         $utility.getJavaType($property.Type) new$utility.capitalize($property.Name)();
-
-#end
-    }
-
     Annotations annotations();
 
     interface Annotations #if( $entityType.baseType )
@@ -244,13 +232,6 @@ public interface $utility.capitalize($entityType.Name)
     @org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "$property.Name", contained = true)
     interface $utility.capitalize($property.Name) 
       extends org.apache.olingo.ext.proxy.api.EntitySetQuery<$javaEntityType, ${javaEntityType}Collection, $utility.capitalize($property.Name)>, AbstractEntitySet<$javaEntityType, $type, ${javaEntityType}Collection> {
-
-    #foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($property)) )
-        #set( $djt = $utility.getJavaType($dos) )
-        #set( $sIdx = $djt.lastIndexOf('.') + 1 )
-        $djt new$djt.substring($sIdx)();
-        ${djt}Collection new$djt.substring($sIdx)Collection();
-    #end
     }
 
   #end

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm
index 2c53164..31b94f3 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm
@@ -18,6 +18,7 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.annotations.EntityType;
 import org.apache.olingo.ext.proxy.api.annotations.Key;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
@@ -29,7 +30,6 @@ import org.apache.olingo.commons.api.edm.constants.EdmContentKind;
 import org.apache.olingo.client.api.edm.ConcurrencyMode;
 #foreach($ns in $namespaces)
 import #if($basePackage)${basePackage}.#end${ns}.*;
-import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
 import org.apache.olingo.commons.api.edm.geo.Geospatial;
@@ -47,6 +47,7 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.Calendar;
 import javax.xml.datatype.Duration;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 @org.apache.olingo.ext.proxy.api.annotations.CompoundKey
 public class $keyRef extends AbstractEntityKey {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/enumType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/enumType.vm b/ext/pojogen-maven-plugin/src/main/resources/enumType.vm
index 9e64b93..5276f76 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/enumType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/enumType.vm
@@ -18,9 +18,11 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.annotations.Namespace;
 import org.apache.olingo.ext.proxy.api.annotations.EnumType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #set( $enumName = $utility.capitalize($enumType.Name) )
 #set( $count = $enumType.MemberNames.size() )

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/singleton.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/singleton.vm b/ext/pojogen-maven-plugin/src/main/resources/singleton.vm
index a84de50..bcee703 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/singleton.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/singleton.vm
@@ -18,13 +18,13 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.AbstractSingleton;
 import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
 import org.apache.olingo.ext.proxy.api.annotations.Singleton;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement;
 #foreach($ns in $namespaces)
-import #if($basePackage)${basePackage}.#end${ns}.*;
 import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
 
@@ -42,6 +42,7 @@ import java.util.UUID;
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Calendar;
+//CHECKSTYLE:ON (Maven checkstyle)
 
 #parse( "${odataVersion}/singleton.vm" )
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/term.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/term.vm b/ext/pojogen-maven-plugin/src/main/resources/term.vm
index 542c7d3..0093933 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/term.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/term.vm
@@ -18,13 +18,14 @@
  *#
 package ${package};
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.ext.proxy.api.annotations.Namespace;
 import org.apache.olingo.ext.proxy.api.annotations.Term;
 import org.apache.olingo.ext.proxy.api.AbstractTerm;
 #foreach($ns in $namespaces)
-import #if($basePackage)${basePackage}.#end${ns}.*;
 import #if($basePackage)${basePackage}.#end${ns}.types.*;
 #end
+//CHECKSTYLE:ON (Maven checkstyle)
 
 @org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
 @org.apache.olingo.ext.proxy.api.annotations.Term(name = "$term.Name",

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm
index 6dcb92e..4c2689e 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm
@@ -19,7 +19,7 @@
 @org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
 @org.apache.olingo.ext.proxy.api.annotations.ComplexType(name = "$complexType.Name")
 public interface $utility.capitalize($complexType.Name) 
-    extends org.apache.olingo.ext.proxy.api.StructuredType,#if($complexType.getBaseType())$utility.getJavaType($complexType.getBaseType().getFullQualifiedName().toString())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($complexType.Name)>#end {
+    extends org.apache.olingo.ext.proxy.api.ComplexType,#if($complexType.getBaseType())$utility.getJavaType($complexType.getBaseType().getFullQualifiedName().toString())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($complexType.Name)>#end {
 
 #if( $entityType.getBaseType() )
   @Override
@@ -40,15 +40,3 @@ public interface $utility.capitalize($complexType.Name)
     #end
 
 #end
-
-    ComplexFactory factory();
-
-    interface ComplexFactory #if( $complexType.baseType )
-           extends ${utility.getJavaType($complexType.getBaseType())}.ComplexFactory#end{
-#foreach($property in $complexProps)
-         @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$property.Name",
-                   type = "$property.Type.FullQualifiedName.toString()")
-         $utility.getJavaType($property.Type) new$utility.capitalize($property.Name)();
-
-#end
-    }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm
index 0f5765f..6b2d0d9 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm
@@ -22,7 +22,7 @@
         isAbstract = $complexType.Abstract#if($complexType.getBaseType()),
         baseType = "$complexType.getBaseType().getFullQualifiedName().toString()"#end)
 public interface $utility.capitalize($complexType.Name) 
-    extends org.apache.olingo.ext.proxy.api.StructuredType,#if($complexType.getBaseType())$utility.getJavaType($complexType.getBaseType().getFullQualifiedName().toString())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($complexType.Name)>#{end}#if( $complexType.isOpenType() ),AbstractOpenType#{end} {
+    extends org.apache.olingo.ext.proxy.api.ComplexType,#if($complexType.getBaseType())$utility.getJavaType($complexType.getBaseType().getFullQualifiedName().toString())#{else}org.apache.olingo.ext.proxy.api.SingleQuery<$utility.capitalize($complexType.Name)>#{end}#if( $complexType.isOpenType() ),AbstractOpenType#{end} {
 
 #if( $entityType.getBaseType() )
   @Override
@@ -74,18 +74,6 @@ public interface $utility.capitalize($complexType.Name)
     #end
 #end
 
-    ComplexFactory factory();
-
-    interface ComplexFactory #if( $complexType.baseType )
-           extends ${utility.getJavaType($complexType.getBaseType())}.ComplexFactory#end{
-#foreach($property in $complexProps)
-         @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$property.Name",
-                   type = "$property.Type.FullQualifiedName.toString()")
-         $utility.getJavaType($property.Type) new$utility.capitalize($property.Name)();
-
-#end
-    }
-
     Annotations annotations();
 
     interface Annotations #if( $complexType.baseType )

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm
index 69d5c37..734ddfb 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm
@@ -25,6 +25,6 @@
   #set( $type = "" )
 #end
 
-@org.apache.olingo.ext.proxy.api.annotations.Singleton(name = "$singleton.Name")
+@org.apache.olingo.ext.proxy.api.annotations.Singleton(name = "$singleton.Name", container = "$container.FullQualifiedName.toString()")
 public interface $utility.capitalize($singleton.Name) extends org.apache.olingo.ext.proxy.api.SingleQuery<$utility.getJavaType($singleton.EntityType)>,AbstractSingleton<$utility.getJavaType($singleton.EntityType), $type, $utility.getJavaType($singleton.EntityType)Collection> {
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/989babb1/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
index ea1570c..6b94b82 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
@@ -1,31 +1,31 @@
-/*
+/* 
  * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
+ * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.olingo.fit.proxy.v3;
 
+//CHECKSTYLE:OFF (Maven checkstyle)
 import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.ext.proxy.Service;
-import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice
-    .DefaultContainer;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
 import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Aliases;
-import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types
-    .ContactDetails;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetails;
 import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
 import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone;
 import org.junit.BeforeClass;
@@ -40,8 +40,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
-//CHECKSTYLE:OFF (Maven checkstyle)
 //CHECKSTYLE:ON (Maven checkstyle)
 
 public abstract class AbstractTestITCase {
@@ -86,11 +84,11 @@ public abstract class AbstractTestITCase {
   }
 
   protected Customer getSampleCustomerProfile(
-      final Integer id,
-      final String sampleName,
-      final DefaultContainer container) {
+          final Integer id,
+          final String sampleName,
+          final DefaultContainer container) {
 
-    final Customer customer = container.getCustomer().newCustomer();
+    final Customer customer = service.newEntity(Customer.class);
 
     // add name attribute
     customer.setName(sampleName);
@@ -98,29 +96,30 @@ public abstract class AbstractTestITCase {
     // add key attribute
     customer.setCustomerId(id);
 
-    final ContactDetails cd = customer.factory().newPrimaryContactInfo();
+    final ContactDetails cd = service.newComplex(ContactDetails.class); // PrimaryContactInfo
     cd.setAlternativeNames(Arrays.asList("alternative1", "alternative2"));
-    cd.setEmailBag(Collections.<String> singleton("myname@mydomain.org"));
-    cd.setMobilePhoneBag(Collections.<Phone> emptySet());
+    cd.setEmailBag(Collections.<String>singleton("myname@mydomain.org"));
+    cd.setMobilePhoneBag(Collections.<Phone>emptySet());
     customer.setPrimaryContactInfo(cd);
 
-    final Aliases aliases = cd.factory().newContactAlias();
-    aliases.setAlternativeNames(Collections.<String> singleton("myAlternativeName"));
+    final Aliases aliases = service.newComplex(Aliases.class);
+    aliases.setAlternativeNames(Collections.<String>singleton("myAlternativeName"));
     cd.setContactAlias(aliases);
 
-    final ContactDetails bcd = customer.factory().newBackupContactInfo();
+    final ContactDetails bcd = service.newComplex(ContactDetails.class); // BackupContactInfo;
     bcd.setAlternativeNames(Arrays.asList("alternative3", "alternative4"));
-    bcd.setEmailBag(Collections.<String> emptySet());
-    bcd.setMobilePhoneBag(Collections.<Phone> emptySet());
-    customer.setBackupContactInfo(Collections.<ContactDetails> singleton(bcd));
+    bcd.setEmailBag(Collections.<String>emptySet());
+    bcd.setMobilePhoneBag(Collections.<Phone>emptySet());
+    customer.setBackupContactInfo(Collections.<ContactDetails>singleton(bcd));
 
+    container.getCustomer().add(customer);
     return customer;
   }
 
   protected void checkSampleCustomerProfile(
-      final Customer customer,
-      final Integer id,
-      final String sampleName) {
+          final Customer customer,
+          final Integer id,
+          final String sampleName) {
 
     assertEquals(id, customer.getCustomerId());
     assertNotNull(customer.getPrimaryContactInfo());