cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Zeigler <robert.zeig...@gmail.com>
Subject bug with nested contexts + map relationships? (3.0M5 & 3.0-SNAPSHOT)
Date Tue, 24 Feb 2009 22:05:06 GMT
While working on a project, I had something like the following:

ObjectContext child = parentContext.createChildDataContext();
List<EntityA> alist = lookupAs();
for(EntityA a : alist) {
   a = child.localObject(a.getObjectId(),null);//note: doing  
localObject(a.getObjectId(),a); still results in the exception
   a.getMapRelationship().containsKey("someKey");//<---- problem line
}

Doing so resulted in:

java.lang.ClassCastException:  
org.apache.cayenne.util.PersistentObjectMap
	at  
org 
.apache 
.cayenne 
.util 
.ObjectContextQueryAction 
.interceptObjectConversion(ObjectContextQueryAction.java:134)
	at  
org 
.apache 
.cayenne 
.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java: 
102)
	at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1343)
	at  
org 
.apache 
.cayenne 
.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java: 
316)
	at  
org 
.apache 
.cayenne 
.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:95)
	at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1343)
	at  
org.apache.cayenne.access.DataContext.performQuery(DataContext.java: 
1332)
	at  
org 
.apache 
.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
	at  
org 
.apache 
.cayenne 
.util.PersistentObjectMap.resolvedObjectMap(PersistentObjectMap.java: 
134)
	at  
org 
.apache 
.cayenne.util.PersistentObjectMap.containsKey(PersistentObjectMap.java: 
233)

A peek at and around ObjectContextQueryAction, line 134, shows:

                     else {

                         // TODO: Andrus 1/31/2006 -  
IncrementalFaultList is not properly
                         // transferred between contexts....

                         List childObjects = new  
ArrayList(objects.size());
                         Iterator it = objects.iterator();
                         while (it.hasNext()) {
                             Persistent object = (Persistent)  
it.next();//this is line 134
                              
childObjects.add(targetContext.localObject(object
                                     .getObjectId(), object));
                         }

                         childResponse.addResultList(childObjects);
                     }

So the next object is a PersistentObjectMap, rather than a "Persistent".
Looks like a bug to me, but I thought I would check to see if I'm just  
missing something obvious before I file a jira.
Note that the code works if, instead of creating a child context, I  
use the parent context (which is a top-level DataContext).

Robert



Mime
View raw message