• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate createCriteria issue

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
alan wamser
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still having this issue...
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alan,

i think it is normal in hibernate to get duplicate entries in the resultlist when using FetchMode.JOIN.

You could get rid of the duplicate entries by doing something like this:



Another way - which i didn't try myself - would be:

 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic