3 Replies Latest reply on Jul 16, 2007 7:08 AM by Michael Hönnig

    hibernate couldn't find column

    Carsten Keuch Newbie

      Hi there,
      i'm new to Hibernate, EJB3 and surrounding stuff. I'm using JBoss 4.0.4 and within delivered Hibernate engine. Database is Postgre 8.1.
      I've a problem with a generated query. The stack trace is (outtake):


      2006-08-01 16:12:53,273 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 42703
      2006-08-01 16:12:53,273 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: column factactual0_.keydate does not exist
      2006-08-01 16:12:53,273 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [select factactual0_.keydate as keydate291_, factactual0_.keyorga as keyorga291_, factactual0_.key as key291_, factactual0_.time as time291_, factactual0_.op_time as op6_291_, factactual0_.max as max291_, factactual0_.min as min291_, factactual0_.op_quantity as op9_291_ from fact_data_actual factactual0_ where factactual0_.keyoperation=? and (factactual0_.keyorga in (1 , 2 , 3))]
      org.postgresql.util.PSQLException: ERROR: column factactual0_.keydate does not exist
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)

      Following the bean code:
       private int keydate, keyorga;
       private float time, task, minTime, maxTime;
       private FactDataActualPK key;
      
       @Id
       public FactDataActualPK getKey() {
       return key;
       }
      
       public void setKey(FactDataActualPK key) {
       this.key = key;
       }
      
       @Column(name = "key_date")
       public int getKeydate() {
       return keydate;
       }
      
       public void setKeydate(int keyDate) {
       this.keydate = keyDate;
       }
      
       @Column(name = "key_orga")
       public int getKeyorga() {
       return keyorga;
       }
      
       public void setKeyorga(int keyOrga) {
       this.keyorga = keyOrga;
       }
      


      Has anybode an idea why Hibernate is saying that the column "keydate" is missing? The sql error sais that the column is not defined! But: The property exists and the @Column Annotation matches the database. The query seems to be correct.
      Thankx for your efforts,

      Regards,

      Carsten.

        • 2. Re: hibernate couldn't find column
          Michael Hönnig Newbie

          I wonder what the solution to this issue was. I have the same problem now:


          // attribute baseComponent
          @javax.persistence.Id
          @javax.persistence.JoinColumn(name="basecomponent_id", columnDefinition="integer")
          @javax.persistence.ManyToOne(fetch=EAGER)
          private BaseComponent baseComponent;
          public BaseComponent getBaseComponent() { return baseComponent; }
          public void setBaseComponent( BaseComponent baseComponent ) { this.baseComponent = baseComponent; }

          results in:

          Hibernate: select component0_.baseComponent as baseComp1_9_, ...

          which of course gives:

          ERROR: column component0_.basecomponent does not exist

          There is no column basecomponent, of course not. That's why I wanted it mapped to basecomponent_id in the JoinColumn annotation.

          What's wrong?

          • 3. Re: hibernate couldn't find column
            Michael Hönnig Newbie

            Ok, I solved it myself.

            The solution is to just do go ahead as usual. But repeat all the annotations but the @Id in the matching attributes of the pk class referred in @IdClass. Thus all these attributes are classes, none is an int (as the key parts are). The int is only used internally.