-->
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.  [ 3 posts ] 
Author Message
 Post subject: FetchMode.JOIN doesn't work for Criteria
PostPosted: Mon Mar 29, 2010 6:00 am 
Newbie

Joined: Fri Mar 19, 2010 12:29 pm
Posts: 12
I have an entity DepartmentEmployee and lazy property department there:
Code:
@ManyToOne (fetch = FetchType.LAZY)
Department department;

For geting department list I use Criteria:
Code:
Criteria cr = session.createCriteria(DepartmentEmployee.class);
cr.setFetchMode("department", FetchMode.JOIN);
cr.add(Restrictions.eq("somekey", "somevalue"));
cr.setProjection(Property.forName("department") );
result = cr.list();

But Department object in this list still lazily initialized.
So why FetchMode.JOIN doesn't work?


Top
 Profile  
 
 Post subject: Re: FetchMode.JOIN doesn't work for Criteria
PostPosted: Mon Mar 29, 2010 1:43 pm 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hi kostepanych

I will paste my mapping which works with my criteria queries using EAGER fetch strategies (queries very similar to your criteria query):

Code:
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name="CUSTOMER_ID", nullable=false)
   public customerAll getCustomerAll()
   {
      return customerAll;
   }



Hope this helps.

Regards, Adam Woźniak


Top
 Profile  
 
 Post subject: Re: FetchMode.JOIN doesn't work for Criteria
PostPosted: Tue Mar 30, 2010 3:10 am 
Newbie

Joined: Fri Mar 19, 2010 12:29 pm
Posts: 12
I've found that FetchMode.JOIN doesn't work when I use cr.setProjection(Property.forName("department")). Without this projection it works good. So, does anybody know why?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.