ImmutableSessionImpl implements Session { @Override @SuppressWarnings("unchecked") public <T> T get(Class<T> clazz, Object id) throws ObjectMapperException { if (clazz == null) { throw new NullPointerException("Class is null."); } final EntityMapping entityMapping = mappingRegistry.getMapping(clazz); final PersistenceAdapter persistenceAdapter = persistenceDelegateFactory.create(id, entityMapping, persistenceContext); LOGGER.debug("Retrieving entity of type {} from {}", clazz, id); return (T) proxyFactory.create(this, entityMapping, persistenceAdapter); } ImmutableSessionImpl(PersistenceContext persistenceContext, PersistenceAdapterFactory persistenceDelegateFactory, MappingRegistry mappingRegistry, ProxyFactory proxyFactory); @Override void close(); @Override void commit(); @Override void delete(Object o); @Override @SuppressWarnings("unchecked") T get(Class<T> clazz, Object id); @Override void save(Object o);  }
@Test public void testGetWithPrimitiveProperties() { final MappingRegistry mappingRegistry = new OnDemandMappingRegistry(new EntityMappingExtractorImpl()); final Session session = new ImmutableSessionImpl(null, new TestingDelegateFactory(), mappingRegistry, new CglibProxyFactory(new PersistenceInterceptorFactoryImpl())); final EntityWithPrimitiveProperties entity = session.get(EntityWithPrimitiveProperties.class, ""); assertThat(entity, notNullValue()); assertThat(entity instanceof EntityWithPrimitiveProperties, is(true)); }
@Test public void testGetWithReferenceProperties() { final MappingRegistry mappingRegistry = new OnDemandMappingRegistry(new EntityMappingExtractorImpl()); final TestingPersistenceContext persistenceContext = new TestingPersistenceContext(); persistenceContext.addProperty("entityWithPrimitiveProperties", ""); final Session session = new ImmutableSessionImpl(persistenceContext, new TestingDelegateFactory(), mappingRegistry, new CglibProxyFactory(new PersistenceInterceptorFactoryImpl())); final EntityWithReferenceProperties entity = session.get(EntityWithReferenceProperties.class, ""); assertThat(entity, notNullValue()); assertThat(entity instanceof EntityWithReferenceProperties, is(true)); final EntityWithPrimitiveProperties referencedEntity = entity.getEntityWithPrimitiveProperties(); assertThat(referencedEntity, notNullValue()); }