title: JPQL (Hibernate implementation) select with join issues
body: <p>I'm having a bit of a rough time with JPQL (using Hibernate).</p>
  
  <p>I have 2 Entities:</p>
  
  <pre><code>package org.oscarehr.common.model;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import javax.persistence.OneToMany;
  import javax.persistence.PrePersist;
  import javax.persistence.JoinColumn;
  import javax.persistence.CascadeType;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  
  @Entity
  @Table(name="spireAccessionNumberMap")
  public class SpireAccessionNumberMap extends AbstractModel&lt;Integer&gt; {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;
      @Column(name="uaccn")
      private Integer uaccn;
  
      @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
      @JoinColumn(name="uaccn_id", referencedColumnName="id")
      private List&lt;SpireCommonAccessionNumber&gt; commonAccessionNumbers = new ArrayList&lt;SpireCommonAccessionNumber&gt;();
  
      public SpireAccessionNumberMap() {
      }
  
      public SpireAccessionNumberMap(Integer uniqueAccn) {
          this.uaccn = uniqueAccn;
      }
  
  
      //@Override
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }   
  
      public Integer getUniqueAccessionNumber() {
          return uaccn;
      }
  
      public void setUniqueAccessionNumber(Integer uaccn) {
          this.uaccn = uaccn;
      }
  
      public List&lt;SpireCommonAccessionNumber&gt; getCommonAccessionNumbers() {
          return commonAccessionNumbers;
      }
  
      @PrePersist
      public void prePersist() {
          Iterator&lt;SpireCommonAccessionNumber&gt; i = this.commonAccessionNumbers.iterator();
          SpireCommonAccessionNumber commonAccessionNumber;
          while(i.hasNext()) {
              commonAccessionNumber = i.next();
              commonAccessionNumber.setUniqueAccessionId(this.uaccn);         
          }
      }
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>package org.oscarehr.common.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  
  @Entity
  @Table(name="spireCommonAccessionNumber")
  public class SpireCommonAccessionNumber extends AbstractModel&lt;Integer&gt; {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;
      @Column(name="caccn")
      private String caccn;
      @ManyToOne
      @JoinColumn(name="uaccn_id", referencedColumnName="id")
      private Integer uaccn_id;
  
  
  
  
      //@Override
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }   
  
      public String getCommonAccessionNumber() {
          return caccn;
      }
  
      public void setCommonAccessionNumber(String caccn) {
          this.caccn = caccn;
      }
  
  
      public Integer getUniqueAccessionId() {
          return uaccn_id;
      }
  
      public void setUniqueAccessionId(Integer uaccn_id) {
          this.uaccn_id = uaccn_id;
      }
  }
  </code></pre>
  
  <p>Basically, I have the 'map' object, which has a unique number associated with it.  The map object has a 'link' to 1 or more 'commonNumber' objects, which store a 'common' number.</p>
  
  <p>The idea is to be able to map lots of common numbers to a unique number using the JPQL and 'Dao's.</p>
  
  <p>However, when I deploy my java WAR file, I get this error:</p>
  
  <pre><code>2013-01-04 13:42:12,344 INFO  [Version:14] Hibernate Commons Annotations 3.1.0.GA
  2013-01-04 13:42:12,347 INFO  [Version:16] Hibernate EntityManager 3.4.0.GA
  2013-01-04 13:42:17,753 ERROR [ContextLoader:215] Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring_jpa.xml]: Invocati
  on of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_
  id references an unknown entity: java.lang.Integer
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
          at org.oscarehr.common.web.OscarSpringContextLoader.createWebApplicationContext(OscarSpringContextLoader.java:97)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
          at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
          at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
          at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
          at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
          at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
          at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
          at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
          at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
          at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
          at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
          at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
          at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
          at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
          at java.lang.Thread.run(Thread.java:679)
  Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_id references an unknown entity: java.lang.Integer
          at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
          at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
          at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
          at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
          at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
          at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
          at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
          at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
          at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
          at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
          ... 28 more
  </code></pre>
  
  <p>I'm at a bit of a loss here...I've tried fiddling around with different ways to map the 'common' object to the 'map' object, but I keep getting errors.</p>
  
  <p>Would anyone be able to shed some light on this for me?</p>