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. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Grails User (Old Archive) - Using formulas to relate to other domain objects

    nabble.com | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
  5. 0

    Dear Hibernate Team, I attempted to enable Envers for a Legacy Hibernate Application which uses hbm.xml based mapping files. The building of the SessionFactory fails due to a class cast exception in the Envers code base. It appears that while generating mapping data in the AuditMetadataGenerator it is assumed that a discriminator is a Column, but it can also be a Formula. This causes a class cast exception to be thrown as is shown below (see the last cause in the exception stack trace). I know the response is going to be attach a test case, but I am not even sure how to create a good test case. Are there instructions on the wiki some where? Some starting project I could use to create the test case? In order to reproduce this issue I think it is as simple as enabling auditing for an entity which has a discriminator based on a formula instead of a column. [2009.11.10 09:33:32.302 XYZ] Failed to initialize due to exception. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionFactory' defined in class path resource [com/xyz/data/spring-config-data.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not init listeners at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:302) at com.XYZ.services.springscope.AbstractXYZSpringScopeStrategy.get(AbstractXYZSpringScopeStrategy.java:87) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184) at $Proxy6.openSession(Unknown Source) at com.XYZ.data.hibernate.conversation.Conversation.<init>(Conversation.java:59) at com.XYZ.data.hibernate.conversation.ConversationManagerImpl.startConversation(ConversationManagerImpl.java:128) at com.XYZ.data.hibernate.conversation.ConversationManagerImpl.beginConversation(ConversationManagerImpl.java:110) at com.XYZ.core.initialization.AbstractInitializationThread.run(AbstractInitializationThread.java:145) at com.XYZ.services.thread.ThreadsManager$ThreadWrapper.run(ThreadsManager.java:147) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.HibernateException: could not init listeners at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205) at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1378) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1367) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:858) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 18 more Caused by: java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column at org.hibernate.envers.configuration.metadata.MetadataTools.addColumns(MetadataTools.java:154) at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateMappingData(AuditMetadataGenerator.java:252) at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:327) at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:87) at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:86) at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99) at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:259) at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198) at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181) at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194) ... 26 more

    Hibernate JIRA | 7 years ago | Kevin Schmidt
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionFactory' defined in class path resource [com/xyz/data/spring-config-data.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not init listeners

    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