-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: list-index column comes up as NULL
PostPosted: Mon Aug 01, 2005 12:38 pm 
Newbie

Joined: Mon Aug 01, 2005 12:15 pm
Posts: 3
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=?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 11:39 am 
Newbie

Joined: Mon Aug 01, 2005 12:15 pm
Posts: 3
i fixed it by following the example under "Can't I have a bidirectional association using a List or Map?" at:

http://www.hibernate.org/116.html?cmd=prntdoc

so if using a list you don't use inverse="true" but insert="false" update="false" at the other end.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.