title: hibernate 4 "unable to find column" error
body: <pre><code>package it.company.tserver.beans.indicatori.ondemand.persistent;
  
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.EnumType;
  import javax.persistence.Enumerated;
  import javax.persistence.FetchType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.OneToMany;
  import javax.persistence.OrderBy;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = &quot;INDICATORS_OD&quot;)
  @NamedQueries( { 
      @NamedQuery(name = &quot;IndicatorOD.getAllIndicators&quot;, query = &quot;SELECT o FROM IndicatorOD o ORDER BY o.description ASC&quot;), 
      @NamedQuery(name = &quot;IndicatorOD.getIndicatorsForType&quot;, query = &quot;SELECT o FROM IndicatorOD o WHERE o.type = :type ORDER BY o.description ASC&quot;), 
      @NamedQuery(name = &quot;IndicatorOD.getReqTemplate&quot;, query = &quot;SELECT o from IndicatorOD j LEFT JOIN j.reqTemplate o where j.codIndicator = :cod ORDER BY o.orderForm ASC&quot;),
      @NamedQuery(name = &quot;IndicatorOD.getRespTemplate&quot;, query = &quot;SELECT o from IndicatorOD j LEFT JOIN j.respTemplate o where j.codIndicator = :cod ORDER BY o.orderForm ASC&quot;)
  })
  
  public class IndicatorOD implements Serializable {
  
      private static final long serialVersionUID = 1626218826909078278L;
  
      public enum IndicatorTypes {
          INDICATOROD, RENDOBBCALC
      }
  
      private String codIndicator;
      private String description;
      private IndicatorTypes type;
  
      private Set&lt;IndicatorODTemplate&gt; reqTemplate = new HashSet&lt;IndicatorODTemplate&gt;();
      private Set&lt;IndicatorODRespTemplate&gt; respTemplate = new HashSet&lt;IndicatorODRespTemplate&gt;();
  
  
      @Id
      @Column(name = &quot;CODE_IND&quot;)
      public String getCodIndicator() {
          return codIndicator;
      }
      public void setCodIndicator(String codIndicator) {
          this.codIndicator = codIndicator;
      }
  
  
      @Column(name = &quot;DESCRIPTION&quot;)
      public String getDescription() {
          return description;
      }
      public void setDescription(String description) {
          this.description = description;
      }
  
  
      @Column(name = &quot;TYPE_IND&quot;)
      @Enumerated(EnumType.STRING)
      public IndicatorTypes getType() {
          return type;
      }
      public void setType(IndicatorTypes type) {
          this.type = type;
      }
  
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @OrderBy(&quot;orderForm ASC&quot;)
      @JoinColumn(name = &quot;CODE_IND&quot;, referencedColumnName = &quot;CODE_IND&quot;)
      public Set&lt;IndicatorODTemplate&gt; getReqTemplate() {
          return reqTemplate;
      }
  
  
      public void setReqTemplate(Set&lt;IndicatorODTemplate&gt; template) {
          this.reqTemplate = template;
      }
      
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @OrderBy(&quot;orderForm ASC&quot;)
      @JoinColumn(name = &quot;CODE_IND&quot;, referencedColumnName = &quot;CODE_IND&quot;)
      public Set&lt;IndicatorODRespTemplate&gt; getRespTemplate() {
          return respTemplate;
      }
  
  
      public void setRespTemplate(Set&lt;IndicatorODRespTemplate&gt; respTemplate) {
          this.respTemplate = respTemplate;
      }
  }
  </code></pre>
  <p>this deploys in jboss 4 with hibernate 3, in jboss 7.1 with hibernate 4 it gives an error :</p>
  <p>org.hibernate.MappingException: <strong>Unable to find column with logical name</strong>: CODE_IND in org.hibernate.mapping.Table(INDICATORS_OD) and its related supertables and secondary tables</p>
  <p>the joincolumn is on the same table, it's not a foreign key to another table, what could be the problem ?</p>
  <p>the table in oracle is :</p>
  <pre><code>  CREATE TABLE &quot;TSERVER&quot;.&quot;INDICATORS_OD&quot; 
     (    &quot;CODE_IND&quot; VARCHAR2(5 BYTE) NOT NULL ENABLE, 
      &quot;DESCRIPTION&quot; VARCHAR2(50 BYTE), 
      &quot;TYPE_IND&quot; VARCHAR2(25 BYTE), 
       CONSTRAINT &quot;PK_INDICATOR_OD&quot; PRIMARY KEY (&quot;CODE_IND&quot;)
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE &quot;TSDATA&quot;  ENABLE
     ) SEGMENT CREATION IMMEDIATE 
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE &quot;TSDATA&quot; ;
  </code></pre>
  <p>19:24:32,328 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011402: Starting Persistence Unit Service 'TServer-4.1.0rc2.jar#oracledb'
  19:24:32,336 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-4) HHH000204: Processing PersistenceUnitInfo [
  name: oracledb
  ...]
  19:24:32,362 INFO  [org.jboss.as.ejb3] (MSC service thread 1-2) JBAS014142: Started message driven bean 'IndicatorODMessagingBean' with 'hornetq-ra' resource adapter
  19:24:33,257 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.persistenceunit.&quot;TServer-4.1.0rc2.jar#oracledb&quot;: org.jboss.msc.service.StartException in service jboss.persistenceunit.&quot;TServer-4.1.0rc2.jar#oracledb&quot;: Failed to start service
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) [rt.jar:1.7.0_261]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622) [rt.jar:1.7.0_261]
  at java.lang.Thread.run(Thread.java:748) [rt.jar:1.7.0_261]
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: oracledb] Unable to build EntityManagerFactory
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
  at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  ... 3 more
  Caused by: org.hibernate.MappingException: <strong>Unable to find column with logical name</strong>: CODE_IND in org.hibernate.mapping.Table(INDICATORS_OD) and its related supertables and secondary tables
  at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:552)
  at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:126)
  at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1428)
  at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:749)
  at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:677)
  at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:626)
  at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
  at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1586)
  at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1359)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
  at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:84)
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
  ... 9 more</p>