java.lang.ClassCastException: org.hibernate.mapping.Formula

Hibernate JIRA | Sven Schliesing | 1 decade ago
  1. 0

    See the attached test (build with ant, place hibernate libraries in lib, run test.Test). Entity Second has a @Formula property. Entity First has a many-to-one association with Second, not on the primary key but on the ALT_ID column, using the "referencedColumnName" attribute of the @JoinColumn annotation. This is NOT the case of an association to a @Formula column (not supported), but a relation on a non-primary column of an entity that happens to have a @Formula property. During SessionFactory creation an exeption is raised: java.lang.ClassCastException: org.hibernate.mapping.Formula at org.hibernate.cfg.BinderHelper.findPropertiesByColumns(BinderHelper.java:234) at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:106) at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:63) at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210) The bug lies in BinderHelper.findPropertiesByColumns. In the iteration starting at line 233, it tries to find the property that maps the "referencedColumnName", but it doesn't consider that some properties may not have a Column, only a Formula. The correct version should be something like this: Iterator columnIt = property.getColumnIterator(); while ( columnIt.hasNext() ) { Object next = columnIt.next(); if (next instanceof Column) { Column column = (Column)next; if ( columnsToProperty.containsKey( column ) ) { columnsToProperty.get( column ).add( property ); } } }

    Hibernate JIRA | 1 decade ago | Salvatore Insalaco
    java.lang.ClassCastException: org.hibernate.mapping.Formula
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 0

    See the attached test (build with ant, place hibernate libraries in lib, run test.Test). Entity Second has a @Formula property. Entity First has a many-to-one association with Second, not on the primary key but on the ALT_ID column, using the "referencedColumnName" attribute of the @JoinColumn annotation. This is NOT the case of an association to a @Formula column (not supported), but a relation on a non-primary column of an entity that happens to have a @Formula property. During SessionFactory creation an exeption is raised: java.lang.ClassCastException: org.hibernate.mapping.Formula at org.hibernate.cfg.BinderHelper.findPropertiesByColumns(BinderHelper.java:234) at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:106) at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:63) at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210) The bug lies in BinderHelper.findPropertiesByColumns. In the iteration starting at line 233, it tries to find the property that maps the "referencedColumnName", but it doesn't consider that some properties may not have a Column, only a Formula. The correct version should be something like this: Iterator columnIt = property.getColumnIterator(); while ( columnIt.hasNext() ) { Object next = columnIt.next(); if (next instanceof Column) { Column column = (Column)next; if ( columnsToProperty.containsKey( column ) ) { columnsToProperty.get( column ).add( property ); } } }

    Hibernate JIRA | 1 decade ago | Salvatore Insalaco
    java.lang.ClassCastException: org.hibernate.mapping.Formula
  4. 0

    Hibernate and @JoinFormula: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column

    Stack Overflow | 3 years ago | Ben
    java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column

    4 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.hibernate.mapping.Formula

      at org.hibernate.cfg.annotations.CollectionBinder.buildOrderByClauseFromHql()
    2. Hibernate
      Configuration.buildSessionFactory
      1. org.hibernate.cfg.annotations.CollectionBinder.buildOrderByClauseFromHql(CollectionBinder.java:603)
      2. org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:454)
      3. org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:408)
      4. org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:382)
      5. org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
      6. org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1012)
      7. org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:238)
      8. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)
      8 frames