HibernateException: null index column for collection

1. Symtom
When access one-to-many relation with collection mapping by list. You may be get this error

Caused by: org.hibernate.HibernateException: null index column for collection: org.ow2.bonita.runtime.model.Execution.executions

at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:710)

at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:379)

at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)

at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)

at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)

at org.hibernate.loader.Loader.doQuery(Loader.java:701)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)

at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)

at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)

Continue reading HibernateException: null index column for collection

spring: java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor

1- Problem

Using spring 4 and hibernate 3.6.10 and got this

Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/spi/SessionFactoryImplementor
  at org.springframework.orm.hibernate4.SessionFactoryUtils.(SessionFactoryUtils.java:92) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:335) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  ... 28 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.spi.SessionFactoryImplementor
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) ~[catalina.jar:7.0.50]
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) ~[catalina.jar:7.0.50]
  ... 32 common frames omitted

2-Solution

Using right version Hibernate for transaction manager and Local session factory bean

  • org.springframework.orm.hibernate3.HibernateTransactionManager
  • org.springframework.orm.hibernate3.LocalSessionFactoryBean

 

<beans:bean id="sessionFactory" name="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <beans:property name="configLocation">
           <beans:value>classpath:hibernate.cfg.xml</beans:value>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>
<beans:bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>