Ok before I break out all the exceptions and code I just want to make sure I understand how Hibernate is supposed to work.
I have an object Company that has many Portfolios, in the Company.hbm.xml it is mapped
<set name="portfolioSet" inverse="true">
<key column="companyID"/>
<one-to-many class="Portfolio"/>
</set>
now when I retrieve a Company object in my DAO
public Company getCompany(Integer id){
Session session = null;
try {
session = SessionFactory.currentSession();
List companyList = session.createCriteria(com.v360.hibernate.model.Company.class)
.add(Expression.eq("id", id))
.list();
return (Company) companyList.get(0);
}
catch (HibernateException e){
throw new RuntimeException(e);
}
finally{
if (session != null)
{
try {
session.close();
}
catch (HibernateException e){
throw new RuntimeException(e);
}
}
}
}
The Company object properities get populated with the appropriate values. How ever when I try to iterate through the Set of Portfolio's I get an exception. Now my question is this, am I suppose to add code to my DAO to populate the Set of Portfolios belonging to a Company or is Hibernate suppose to do this on the retrieveal of the Company?
If Hibernate is suppose to then I'll post my code and all my exceptions.
Regards,
JR
|