Project

General

Profile

Revision aa719982

IDaa7199823ae5cca4ecc0cb34f2b955bf8bdf7c36
Parent 79820313
Child f8dac431

Added by Andreas Kohlbecker almost 4 years ago

fixing wrong handling of proxies which are hidden in collections

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CacheLoader.java
278 278
    /**
279 279
     * Load the <code>cdmEntity</code> graph recursively into the cache and
280 280
     * updates entity which are already in the cache depending on the value of
281
     * <code>update</code>, for mor in depth details on this mechanism see
281
     * <code>update</code>, for more in depth details on this mechanism see
282 282
     * {@link #getCdmBaseTypeFieldValue(CdmBase, CdmBase, String, List, boolean)}.
283 283
     *
284 284
     *
......
295 295
     */
296 296
    private CdmBase loadRecursive(CdmBase cdmEntity,  List<Object> alreadyVisitedEntities, boolean update) {
297 297

  
298
        CdmBase cachedCdmEntity = load(cdmEntity);
298
        CdmBase cdmEntityDeproxied = (CdmBase)ProxyUtils.deproxyOrNull(cdmEntity);
299
        if(cdmEntity == null){
300
            return cdmEntity;
301
        } else {
302
            cdmEntity = cdmEntityDeproxied;
303
        }
299 304

  
305
        CdmBase cachedCdmEntity = load(cdmEntity);
300 306

  
301 307
        // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
302 308
        // since there could be new or deleted objects in the cdmEntity sub-graph
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/ProxyUtils.java
156 156
        return o;
157 157
    }
158 158

  
159
    /**
160
     * de-proxies the passed object <code>o</code> if it is an initialized proxy object,
161
     * otherwise <code>null</code> is returned.
162
     */
163
    public static Object deproxyOrNull(Object o) {
164
        if(o != null && o instanceof HibernateProxy) {
165
            LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
166
            if(!hli.isUninitialized()) {
167
                return hli.getImplementation();
168

  
169
            }
170
        }
171

  
172
        if(o != null && o instanceof PersistentCollection) {
173
            PersistentCollection pc = ((PersistentCollection)o);
174
            if(pc.wasInitialized()) {
175
                return  ProxyUtils.getObject(pc);
176

  
177
            }
178
        }
179
        return null;
180
    }
181

  
159 182
    public static boolean isUninitializedProxy(Object o) {
160 183
        if(o != null && o instanceof HibernateProxy) {
161 184
            LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)