-->
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.  [ 4 posts ] 
Author Message
 Post subject: Need help with using setFetchMode
PostPosted: Thu Apr 15, 2010 3:12 pm 
Newbie

Joined: Thu Apr 01, 2010 1:05 pm
Posts: 4
Hello,

Not been successful using setFetchMode. I want to dynamically fetch lazy to eager. Please let me know if anyone has used successfully in their project. Here is my code.

In the main class I have borrower has lazy:

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,targetEntity = Borrower.class)
@JoinColumn(name="ID_LOAN")
private Set mBorrowers = null;

While creating query I change it to JOIN
Criteria query = session.createCriteria(Loan.class) .setFetchMode("Borrower", FetchMode.JOIN);
query.setMaxResults(1);

I still get the LAZY behaviour. Does any one tell me what I am doing wrong? I appreceaite your help and time.


Top
 Profile  
 
 Post subject: Re: Need help with using setFetchMode
PostPosted: Thu Apr 15, 2010 5:07 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
Hello, i think you have a typo in either of the things that you wrote.

Assuming that the mapping it's ok the criteria and that your access strategy it's field instead of property, it should be
Code:
Criteria query = session.createCriteria(Loan.class).setFetchMode("mBorrowers", FetchMode.JOIN);
query.setMaxResults(1);


assuming that the code it's ok, should be

Code:
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name="ID_LOAN")
private Set<Borrower> borrowers;


i hope that could help solve your problem,

Regards,


Top
 Profile  
 
 Post subject: Re: Need help with using setFetchMode
PostPosted: Thu Apr 15, 2010 6:01 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Code:
Criteria query = session.createCriteria(Loan.class).setFetchMode("mBorrowers", FetchMode.JOIN);
query.setMaxResults(1);


query.setMaxResults(1); returns an instance of Criteria object. how are you evaluating the results? did you mean
query.setMaxResults(1).list(); ?

also i think it is the value of the Set variable that you should use in the association
if it is
private Set borrowers = null;
then

Code:
Criteria query = session.createCriteria(Loan.class).setFetchMode("borrowers", FetchMode.JOIN);
query.setMaxResults(1).list();


Hope this helps!


Top
 Profile  
 
 Post subject: Re: Need help with using setFetchMode
PostPosted: Fri Apr 16, 2010 10:02 am 
Newbie

Joined: Thu Apr 01, 2010 1:05 pm
Posts: 4
Thanks a lot guys. It worked.


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