My Department class has a arraylist holding employee's. When I add a new employee to my DB the list-index column comes up as NULL.
Hibernate version: 3.0.5
Mapping documents:
Department.hbm.xml:
<list name="employees" inverse="true" cascade="all-delete-orphan">
<key column="EMPLOYEE_ID"/>
<list-index column="EMPLOYEE_sortOrder" />
<one-to-many class="Employee"/>
</list>
Employee.hbm.xml:
<many-to-one name="department" column="DEPARTMENT_ID"
class="Department" not-null="true"/>
Code between sessionFactory.openSession() and session.close():
Session hSession = HibernateUtil.currentSession();
Transaction tx = hSession.beginTransaction();
Department d = (Department) hSession.createQuery("from Department where name=?")
.setString(0,employee.getDepartmentName())
.uniqueResult();
employee.setDepartment(d);
employee.getDepartment().getEmployees().add(employee);
tx.commit();
HibernateUtil.closeSession();
Full stack trace of any exception that occurs:
javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'list' from bean of type DepartmentList: org.hibernate.HibernateException: null index column for collection: Department.employees
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.register_jsp._jspService(register_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
Name and version of the database you are using:
mysql 4.1.9
The generated SQL (show_sql=true):
Hibernate: select department0_.DEPARTMENT_ID as DEPARTMENT1_, department0_.name as name97_ from DEPARTMENT department0_
Hibernate: select projects0_.PROJECT_ID as PROJECT1_1_, projects0_.PROJECT_sortOrder as PROJECT5_1_, projects0_.PROJECT_ID as PROJECT1_0_, projects0_.DEPARTMENT_ID as DEPARTMENT2_99_0_, projects0_.name as name99_0_, projects0_.description as descript4_99_0_ from PROJECT projects0_ where projects0_.PROJECT_ID=?
Hibernate: select employees0_.EMPLOYEE_ID as EMPLOYEE1_1_, employees0_.EMPLOYEE_sortOrder as EMPLOYEE7_1_, employees0_.EMPLOYEE_ID as EMPLOYEE1_0_, employees0_.DEPARTMENT_ID as DEPARTMENT2_96_0_, employees0_.name as name96_0_, employees0_.email as email96_0_, employees0_.password as password96_0_, employees0_.isManager as isManager96_0_ from EMPLOYEE employees0_ where employees0_.EMPLOYEE_ID=?
Hibernate: select projects0_.PROJECT_ID as PROJECT1_1_, projects0_.PROJECT_sortOrder as PROJECT5_1_, projects0_.PROJECT_ID as PROJECT1_0_, projects0_.DEPARTMENT_ID as DEPARTMENT2_99_0_, projects0_.name as name99_0_, projects0_.description as descript4_99_0_ from PROJECT projects0_ where projects0_.PROJECT_ID=?
Hibernate: select employees0_.EMPLOYEE_ID as EMPLOYEE1_1_, employees0_.EMPLOYEE_sortOrder as EMPLOYEE7_1_, employees0_.EMPLOYEE_ID as EMPLOYEE1_0_, employees0_.DEPARTMENT_ID as DEPARTMENT2_96_0_, employees0_.name as name96_0_, employees0_.email as email96_0_, employees0_.password as password96_0_, employees0_.isManager as isManager96_0_ from EMPLOYEE employees0_ where employees0_.EMPLOYEE_ID=?
|