1 Reply Latest reply on Feb 9, 2006 4:21 PM by Emmanuel Bernard

    Association does not infer the correct column name

    Peter Russell Newbie

      I am using Embedded EJB to unit test my Entity Beans. I have 2 tables dept and emp, dept having a one-to-many association wuth emp.

      if I define the association:

      @javax.persistence.OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = javax.persistence.FetchType.EAGER)
       @javax.persistence.JoinColumn(name = "dept_id")
       public java.util.Collection<tv.probability.referenceimplementation.dto.EmpDTOImpl> getEmps() {
       return emps;
       }


      and do not define the column in the emp EJB, but leave the container to infer it through the naming convention:

      @javax.persistence.Id @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
       public int getEmpId() {
       return empId;
       }
      


      I get the exception:

      org.hibernate.exception.SQLGrammarException: could not load an entity: [tv.probability.referenceimplementation.dto.DeptDTOImpl#19]


      and the SQL:
      Hibernate: select deptdtoimp0_.dept_id as dept1_0_1_, deptdtoimp0_.dept_name as dept2_0_1_, emps1_.dept_id as dept3_3_, emps1_.empId as empId3_, emps1_.empId as empId1_0_, emps1_.emp_name as emp2_1_0_ from dept deptdtoimp0_ left outer join emp emps1_ on deptdtoimp0_.dept_id=emps1_.dept_id where deptdtoimp0_.dept_id=?
      WARN 05-02 11:33:42,067 (JDBCExceptionReporter.java:logExceptions:71) -SQL Error: 1054, SQLState: 42S22
      ERROR 05-02 11:33:42,070 (JDBCExceptionReporter.java:logExceptions:72) -null, message from server: "Unknown column 'emps1_.empId' in 'field list'"


      This looks like a bug, but maybe I have misunderstood the inference of column names

      Pete