1 Reply Latest reply on Sep 20, 2005 11:14 AM by Audun Wilhelmsen

    OneToOne - Unknown column 'competence0_nCompetenceID' in 'fi

    Audun Wilhelmsen Newbie

      What wrong with this code ?

      @Entity
      @Table(name="Competence")
      public class Competence implements java.io.Serializable {
       private int competenceID;
       private Employee employee;
      
       @Id(generate = GeneratorType.AUTO)
       @Column(name="nCompetenceID", unique=true)
       public int getCompetenceID() {
       return this.competenceID;
       }
      
       public void setCompetenceID(int competenceID) {
       this.competenceID = competenceID;
       }
      
       @OneToOne(cascade = CascadeType.ALL)
       @JoinColumn(insertable=false, updatable=false, name="cEmployeeID")
       public Employee getEmployee() {
       return this.employee;
       }
      
       public void setEmployee(Employee employee) {
       this.employee = employee;
       }
      }
      
      @Entity
      @Table(name = "Employee")
      public class Employee implements java.io.Serializable {
       private String employeeID;
       private Competence competence;
      
       @Id
       @Column(name="EMPLOYEEID", unique=true)
       public String getEmployeeID() {
       return this.employeeID;
       }
      
       public void setEmployeeID(String employeeID) {
       this.employeeID = employeeID;
       }
      
       @OneToOne(mappedBy="employee", fetch=FetchType.LAZY)
       public Competence getCompetence() {
       return this.competence;
       }
      
       public void setCompetence(Competence competence) {
       this.competence = competence;
       }
      }


      Database script(mySQL):
      CREATE TABLE `EMPLOYEE` (
       `EMPLOYEEID` VARCHAR(5) NOT NULL,
       `COMPANYID` VARCHAR(5) NOT NULL,
       `NAME` VARCHAR(25) NOT NULL,
       `SURNAME` VARCHAR(25) NOT NULL,
       `MOBILE` VARCHAR(16) NULL,
       `EMAIL` VARCHAR(20) NULL,
       `COMMISSION` NUMERIC NOT NULL,
       `PARTTIME` NUMERIC NULL,
       `ROLE` VARCHAR(50) NOT NULL,
       `INTERNAL` VARCHAR(1) NOT NULL,
       `INACTIVEDATE` DATETIME NULL,
       `cPASSWORD` VARCHAR(100) NULL,
       PRIMARY KEY(`EMPLOYEEID`)
      );
      
      CREATE TABLE `Competence` (
       `cCompetenceID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
       `cEmployeeID` VARCHAR(5) NOT NULL,
       `cDescription` LONGTEXT NOT NULL,
       `dtgModified` DATETIME NOT NULL,
       `dtgCreated` DATETIME NOT NULL,
       PRIMARY KEY(`cCompetenceID`),
       INDEX `Competence_FKIndex1`(`cEmployeeID`),
       FOREIGN KEY(`cEmployeeID`)
       REFERENCES `EMPLOYEE`(`EMPLOYEEID`)
       ON DELETE NO ACTION
       ON UPDATE NO ACTION
      );


      Employee entity work fine alone, but when I tried to create a OneToOne connection, I got following error...

      [org.hibernate.util.JDBCExceptionReporter] could not load an entity: [no.antares.domain.Competence#adm] [select competence0_.nCompetenceID as nCompete1_1_1_, competence0_.cDescription as cDescrip2_1_1_, competence0_.dtgModified as dtgModif3_1_1_, competence0_.dtgCreated as dtgCreated1_1_, competence0_.cEmployeeID as cEmploye5_1_1_, employee1_.EMPLOYEEID as EMPLOYEEID4_0_, employee1_.NAME as NAME4_0_, employee1_.COMMISSION as COMMISSION4_0_, employee1_.COMPANYID as COMPANYID4_0_, employee1_.EMAIL as EMAIL4_0_, employee1_.INACTIVEDATE as INACTIVE6_4_0_, employee1_.INTERNAL as INTERNAL4_0_, employee1_.MOBILE as MOBILE4_0_, employee1_.PARTTIME as PARTTIME4_0_, employee1_.ROLE as ROLE4_0_, employee1_.SURNAME as SURNAME4_0_ from Competence competence0_ left outer join Employee employee1_ on competence0_.cEmployeeID=employee1_.EMPLOYEEID where competence0_.cEmployeeID=?]
      java.sql.SQLException: Unknown column 'competence0_.nCompetenceID' in 'field list'