cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Pardeike ...@fsys.se>
Subject Bug in prepareForAccess@BaseContext ?
Date Tue, 18 Mar 2008 13:55:21 GMT
Hi,

maybe I am totally off here, but I just tried to find out why my to- 
one relationship did not work and I went and traced the code for  
3.0M3. Seems something is wrong in prepareForAccess@BaseContext:

This is my version and to me this looks like 'objects[0]' is never  
really used (see marker ? >>>>). As a result,  
'object.getPersistenceState()' will of course still be  
PersistenceState.HOLLOW and the FaultFailureException is thrown.

Regards,
Andreas Pardeike



     public void prepareForAccess(Persistent object, String property,  
boolean lazyFaulting) {
        if (object.getPersistenceState() == PersistenceState.HOLLOW) {

            ObjectId oid = object.getObjectId();
            List<?> objects = performQuery(new ObjectIdQuery(oid,  
false, ObjectIdQuery.CACHE));

            if (objects.size() == 0) {
                throw new FaultFailureException(
                        "Error resolving fault, no matching row exists  
in the database for ObjectId: "
                                + oid);
            }
            else if (objects.size() > 1) {
                throw new FaultFailureException(
                        "Error resolving fault, more than one row  
exists in the database for ObjectId: "
                                + oid);
            }
? >>>>
            // sanity check...
            if (object.getPersistenceState() !=  
PersistenceState.COMMITTED) {

                String state =  
PersistenceState.persistenceStateName(object
                        .getPersistenceState());

                // TODO: andrus 4/13/2006, modified and deleted states  
are possible due to
                // a race condition, should we handle them here?

                throw new FaultFailureException(
                        "Error resolving fault for ObjectId: "
                                + oid
                                + " and state ("
                                + state
                                + "). Possible cause - matching row is  
missing from the database.");
            }
        }

        // resolve relationship fault
        if (lazyFaulting && property != null) {
            Property propertyDescriptor =  
getEntityResolver().getClassDescriptor(
                     
object.getObjectId().getEntityName()).getProperty(property);

            // this should trigger fault resolving
            propertyDescriptor.readProperty(object);
        }
    }

Mime
View raw message