Tuesday, November 5, 2013

AnnotationException No identifier specified for entity

Sometimes a foolish mistake could drag me few hours to resolve although it is simple. At one time I was rushing to commit my code. But what a surprise is that I got this error throw out during unit test and I don't know what is really happening?
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: org.huahsin.Rocket.Entity
 at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:243)
 at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:663)
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3406)
 at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3360)
 at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1334)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
 at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:251)
 at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
 at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
 ... 14 more
I spent few hours on this searching and I found a silly mistake happened in my datasource-spring.xml:
 ...
 ...
 <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
  <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
  <property name="dataSource" ref="dataSource"/>
  <property name="packagesToScan" value="org.huahsin.Rocket.*"/>
 </bean>
packagesToScan is expecting a value of package name. org.huahsin.Rocket is a valid package name whereas org.huahsin.Rocket.* is not. I'm old. My eyes wasn't as good as when I was young. My eyes couldn't spot the tiny little star.

No comments: