Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1628

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1M3
    • 3.1B1
    • Core Library
    • 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.

      Attachments

        Activity

          People

            demitri Dzmitry Kazimirchyk
            demitri Dzmitry Kazimirchyk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: