Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.1M3
-
None
Description
ClassCastException (PersistentObjectSet to PersistentObject or PersistentObjectMap to PersistentObject) is thrown if using java.util.Set or java.util.Map as collection type for to-many relationship:
Exception in thread "main" java.lang.ClassCastException: org.apache.cayenne.util.PersistentObjectSet cannot be cast to org.apache.cayenne.Persistent
at org.apache.cayenne.util.ObjectContextQueryAction.interceptObjectConversion(ObjectContextQueryAction.java:137)
at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:97)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:990)
at org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:336)
at org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:104)
at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:91)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:990)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:979)
at org.apache.cayenne.util.RelationshipFault.resolveFromDB(RelationshipFault.java:89)
at org.apache.cayenne.util.PersistentObjectSet.resolvedObjectSet(PersistentObjectSet.java:237)
at org.apache.cayenne.util.PersistentObjectSet.size(PersistentObjectSet.java:210)
When parent context intercepts relationship query and finds in its ObjectStore something which is not List it wraps it in a List and then returns as a response. After that while transfering result to target context it tries to cast all objects from the List to PersistentObject, so we get ClassCastException.