posted April 12, 2006 03:59 PM
——————————————————————————–
I have two tables mapped using hibernate (jobApplication, jobApplicationComments).
The jobApplication object has the following details…
<set name=”jobApplicationComments” inverse=”true” order-by=”CREATED_DATE” >
<key>
<column name=”APPLICATION_ID” precision=”22″ scale=”0″ not-null=”true” />
</key>
<one-to-many class=”com.haysmed.jobapplication.hibernate.JobApplicationComments” />
</set>
with the following in the class…
private Set jobApplicationComments = new HashSet(0);
In my business logic I search for all applications using the following.
Criteria crit = session.createCriteria(JobApplication.class)
.setFetchMode(“jobApplicationComments”, FetchMode.JOIN)
.add(Expression.or(Expression.like(“firstName”, “%”+name+”%”).ignoreCase(),Expression.like(“lastName”, “%”+name+”%”).ignoreCase()))
.addOrder(Order.desc(“createdDate”));
The problem is that when i set the FetchMode the results are incorrect. I’m getting an application for each comments. So if and application has 5 comments, there are 5 entries in the list. Looks like an outer join.
If I remove the setFetchMode I receive the failed to lazily initialize a collection for the comments object.
So what am I missing????