3

I am starting a new project and this is my first experience with Hibernate 4 and using Spring 3 without the hibernate templates.

Here are two of my entity classes: (This appears to happen on all of them)

/**
 * Tweener to connect multiple dictionary entries in various ways
 * @author thom
 */
@Entity
@Table( name = "CROSS_REF",
        uniqueConstraints=    @UniqueConstraint(columnNames = {"FROM_ENTRY_UUID", "TO_ENTRY_UUID", "XREF_TYPE"})
)
public class CrossReference     extends Pojo 
                                 implements Comparable<CrossReference>{
    /**
     * Cross reference types
     * @author thom
     */
    public enum XrefType{
        /**
         * Another way to spell this word
         */
        alternateSpelling,
        /**
         * Word you get by adding or removing a letter
         */
        hook,
        /**
         * Root word with additional endings
         */
        variation
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "FROM_ENTRY_UUID", referencedColumnName = "UUID", nullable=false)
    private DictionaryEntry     fromEntry;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "TO_ENTRY_UUID", referencedColumnName = "UUID", nullable=false)
    private DictionaryEntry     toEntry;

    @Column(name = "XREF_TYPE", nullable = false)
    private XrefType            xrefType;
...

and it's super class:

/**
 * Base class for all POJO objects
 * @author Heavyweight software
 */
public class Pojo {
  public static final long      EMPTYUUID   = -1;

  /**
   * Convert a calendar into a formatted timestamp useful for display
   * @param date the calendar being strung
   * @return a standardized time stamp version of a calendar
   */
  @Transient
  public static String getTimestamp(Calendar date) {
    if(date==null){
      return "";
    }

    DateFormat formatter = DateFormat.getDateTimeInstance();
    String str = formatter.format(date.getTime());
    return str;
  }

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  @Column(name = "UUID", nullable = false, unique = true)
  protected Long uuid = EMPTYUUID;

and this is my error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testSessionFactory' defined in URL [file:/home/thom/workspace/LexDataAccess/bin/config/test-dao-spring.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.heavyweight.lexaholic.model.lexicon.CrossReference
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at com.heavyweight.lexaholic.dao.hibernate.HibernateTestSchema.initBeanFactory(HibernateTestSchema.java:42)
    at com.heavyweight.lexaholic.dao.hibernate.HibernateTestSchema.getBeanFactory(HibernateTestSchema.java:50)
    at com.heavyweight.lexaholic.dao.hibernate.HibernateTestSchema.getDictionaryEntryDAO(HibernateTestSchema.java:74)
    at com.heavyweight.lexaholic.dao.hibernate.lexicon.DictionaryEntryHibernateDAOTest.setUp(DictionaryEntryHibernateDAOTest.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.heavyweight.lexaholic.model.lexicon.CrossReference
    at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:664)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3448)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3402)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1330)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1780)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
    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:1545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
    ... 34 more

All the research I'm doing says that this error is caused by a missing @Id, but, as you can see, I have it. Is it a problem with the base class and Hibernate 4?

1 Answer 1

9

I think you should add @MappedSuperclass on Pojo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.