java.lang.ClassCastException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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 ); } } }
    via by Salvatore Insalaco,
  • 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 ); } } }
    via by Salvatore Insalaco,
    • 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)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,