java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column

Hibernate JIRA | Michael Simons | 4 years ago
  1. 0

    Given a mapping like {code} @ManyToOne(fetch=FetchType.EAGER, optional=false) @JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula=@JoinFormula(value=Titel.DOMAIN_FORMULA, referencedColumnName="rv_domain")), @JoinColumnOrFormula(column=@JoinColumn(name="titel", referencedColumnName="rv_low_value")) }) @Fetch(FetchMode.JOIN) @NotNull private Titel titel; {code} where Titel is a subtype of a DomainValue: {code} @Entity @DiscriminatorValue(Titel.DOMAIN) public class Titel extends DomainValue { private static final long serialVersionUID = 5804243997732685958L; public final static String DOMAIN = "TITEL"; public final static String DOMAIN_FORMULA = "'" + DOMAIN + "'"; } {code} base class DomainValue {code} @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @Cacheable(true) @Cache(usage=CacheConcurrencyStrategy.READ_ONLY) @Immutable @Table(name="cg_ref_codes") @IdClass(DomainValue.PrimaryKey.class) @DiscriminatorColumn(name="rv_domain") public class DomainValue implements Serializable { ... } {code} the @NotNull leads to a class cast exception while starting the persistence unit: {code} java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyNotNull(TypeSafeActivator.java:314) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyConstraints(TypeSafeActivator.java:247) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:209) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:186) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:158) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:110) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] {code} Mapping seams to work, though. But i guess the validation isnt't in place.

    Hibernate JIRA | 4 years ago | Michael Simons
    java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
  2. 0

    Given a mapping like {code} @ManyToOne(fetch=FetchType.EAGER, optional=false) @JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula=@JoinFormula(value=Titel.DOMAIN_FORMULA, referencedColumnName="rv_domain")), @JoinColumnOrFormula(column=@JoinColumn(name="titel", referencedColumnName="rv_low_value")) }) @Fetch(FetchMode.JOIN) @NotNull private Titel titel; {code} where Titel is a subtype of a DomainValue: {code} @Entity @DiscriminatorValue(Titel.DOMAIN) public class Titel extends DomainValue { private static final long serialVersionUID = 5804243997732685958L; public final static String DOMAIN = "TITEL"; public final static String DOMAIN_FORMULA = "'" + DOMAIN + "'"; } {code} base class DomainValue {code} @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @Cacheable(true) @Cache(usage=CacheConcurrencyStrategy.READ_ONLY) @Immutable @Table(name="cg_ref_codes") @IdClass(DomainValue.PrimaryKey.class) @DiscriminatorColumn(name="rv_domain") public class DomainValue implements Serializable { ... } {code} the @NotNull leads to a class cast exception while starting the persistence unit: {code} java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyNotNull(TypeSafeActivator.java:314) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyConstraints(TypeSafeActivator.java:247) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:209) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:186) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:158) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:110) ~[hibernate-core-4.1.11.Final.jar:4.1.11.Final] {code} Mapping seams to work, though. But i guess the validation isnt't in place.

    Hibernate JIRA | 4 years ago | Michael Simons
    java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
  3. 0

    Using @JoinFormula with composite key throw ClassCastException org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column {noformat} org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:203) at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:187) at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:181) at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:172) at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25) at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:584) at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1596) Error performing callback invocation : org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:871) at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:786) at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:725) at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:200) ... 11 more org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:203) at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:187) at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:181) at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:172) at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25) at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:584) at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1596) at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:871) at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:786) at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:725) at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:200) ... 11 more {noformat}

    Hibernate JIRA | 1 month ago | Flemming Harms
    org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    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 cannot be cast to org.hibernate.mapping.Column

      at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyNotNull()
    2. Hibernate
      TypeSafeActivator.activate
      1. org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyNotNull(TypeSafeActivator.java:314)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      2. org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyConstraints(TypeSafeActivator.java:247)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      3. org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:209)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      4. org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:186)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      5. org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:158)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      6. org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:110)[hibernate-core-4.1.11.Final.jar:4.1.11.Final]
      6 frames