Cayenne
  1. Cayenne
  2. CAY-1628

ClassCastException when using java.util.Set or java.util.Map as collection type for to-many relationship

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1M3
    • Fix Version/s: 3.1B1
    • Component/s: Core Library
    • Labels:
      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.

        Activity

          People

          • Assignee:
            Dzmitry Kazimirchyk
            Reporter:
            Dzmitry Kazimirchyk
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development