2

I'm using Hibernate in my project with a Oracle Database.

I have an object called RefertoDO with a reference to another table:

@Entity
@Table(name = "REFERTO")
public class RefertoDO implements Serializable {
... 
  @JoinColumn(name = "NUM_PROG_ID")
  @ManyToOne(fetch = FetchType.LAZY)
  private AnagraficaDO anagrafica;
...
}

EDIT3: here is the other table

 @Entity
 @Table(name = "ANAGRAFICA")
 @Indexed
 public class AnagraficaDO implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "NUM_PROG_ID")
    @Fields({ @Field(index = Index.YES, store = Store.YES) })
    private Long numProgId; 

    ... 
    }

When I start the project with Tomcat 8 in IntelliJ 15.2 (but I was having the problem even with v14) I get this error:

Caused by: org.hibernate.MappingException: Unable to find column with logical name num_prog_id in table REFERTO

This only happens in IntelliJ; if I switch to Eclipse, or if I run the project from a standalone tomcat (generating the WAR) everything is fine.

I was also using JRebel but I have done many tests disabling it so I don't believe is much involved.

obviously the num_prog_id is present both in the table REFERTO and in the table ANAGRAFICA.

EDIT: a coworker suggested to me that this problem happens only with java8. If I switch to java7, the problem goes away. I have updated title and body of the question.

EDIT2: here is the DDL for Referto.

CREATE TABLE "REFERTO" 
   (    "ANNO_REFERTO" NUMBER(4,0), 
    "NUMERO_REFERTO" NUMBER(9,0), 
    "TIPO_REFERTO" VARCHAR2(8 BYTE), 
    "DATA_RICHIESTA" DATE, 
    "ANNO_DONAZIONE" NUMBER(4,0), 
    "NUMERO_UNITA" NUMBER(9,0), 
    "CODICE_PRODOTTO" VARCHAR2(8 BYTE), 
    "NUM_PROG_DON" NUMBER(6,0), 
    "NUM_PROG_PAZ" NUMBER(6,0), 
    "NUM_ESAMI_PREN" NUMBER(3,0), 
    "NUM_ESAMI_EFFET" NUMBER(3,0), 
    "CODICE_PATOLOGIA" VARCHAR2(8 BYTE), 
    "CODICE_TESTO" VARCHAR2(8 BYTE), 
    "REFERTO_STAMPATO" VARCHAR2(1 BYTE), 
    "SCARICATO_CONCERTO" VARCHAR2(1 BYTE), 
    "CATEGORIA_CONTATTO" VARCHAR2(8 BYTE), 
    "CUO" VARCHAR2(5 BYTE), 
    "VALIDITA" VARCHAR2(1 BYTE), 
    "OPER_VALIDITA" VARCHAR2(20 BYTE), 
    "DATA_VALIDITA" DATE, 
    "CUO_PROV" VARCHAR2(5 BYTE), 
    "ANNO_DONAZIONE_PROV" NUMBER(4,0), 
    "NUMERO_UNITA_PROV" NUMBER(9,0), 
    "REFERTO_SCARICATO" VARCHAR2(1 BYTE), 
    "STRID_DOCUMENTO_ESTERNO" VARCHAR2(30 BYTE), 
    "FLAG_CDA2" VARCHAR2(1 BYTE), 
    "ID_PRESIDIO" VARCHAR2(8 BYTE), 
    "CDA2_CONFIDENTIALITY_CODE" VARCHAR2(2 BYTE) DEFAULT '01', 
    "NUM_PROG_ID" NUMBER(16,0), 
    "NUM_PROG_ID_ALS" NUMBER(16,0), 
    "STORICIZZATO" NUMBER(1,0), 
    "ESAMI_STORICIZZATI" NUMBER(1,0)
    ) ;

Any Idea of what's going on?

musikele
  • 355
  • 2
  • 15
  • Provide DDL for `REFERTO` table. Just for cross verification. – Ambrish Jan 08 '16 at 10:47
  • @Ambrish DDL posted. – musikele Jan 15 '16 at 11:14
  • Table colums are actually not checked during session factory startup, you would see the error about column lately when running SQL. `num_prog_id` refers to the **logical name** which in hibernate means entity field (or property) not table column. So you should also show the mappings for `AnagraficaDO`, the problem is more likely there. Also I would double check the _java7 difference_, mapping problems are usually not java version specific. – vnov Jan 18 '16 at 06:46
  • Hi. Well I found out that at the very start of Hibernate it tries to check for tables and columns; this happens even in tests: a junit run with jdk 1.8 will fail, a junit lunched with jdk 1.7 will not. I'll put the "relevant" mapping for AnagraficaDO too, if it might be of any help. – musikele Jan 18 '16 at 17:16
  • OK I don't see anything in `AnagraficaDO `, you may also post exception stack, its not clear what is hibernate actually doing. Also what version of hibernate are you using? – vnov Jan 20 '16 at 11:59
  • I am using hibernate4. – musikele Jan 21 '16 at 13:57
  • After a lot of experiments, this is what we have discovered. There was another Entity that was referencing `RefertoDO`, and this was causing the issue. We just added a simple `@Column(name="NUM_PROG_ID") private Long numProgId` to RefertoDO, along with the previously defined relation, and everything is working fine. But we have still no clue about what's going on. – musikele Jan 21 '16 at 13:59

0 Answers0