-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria.setFetchMode
PostPosted: Tue Oct 02, 2012 12:18 am 
Newbie

Joined: Tue Jul 31, 2012 11:39 pm
Posts: 2
Hi,

I have a entity which has many ManytoOne relationships with other entities. Like:


public class Test{
private Long id;
private Package package;
private SystemInUse systemInUse;
@Id
@GeneratedValue(strategy = AUTO)
@Column(name = "security_id", unique = true, nullable = false)
public Long getId()
{
return this.id;
}
@ManyToOne(fetch = FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "package_id", nullable = false)
public SecurityType getPackage()
{
return this.package;
}
@ManyToOne(fetch = FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "systemInUse_id", nullable = false)
public SecurityType getSystemInUse()
{
return this.systemInUse;
}
}

in my main entity class.
In one query i need to fetch all the records in this 'Test' table and attached records for 'Package' .
I use the following criteria
Criteria secCrit=securityDao.getSessionFactory().getCurrentSession().createCriteria(Test.class);
secCrit.setFetchMode("package", FetchMode.JOIN);
secCrit.setFirstResult(firstResult);
if(maxResults!=0)
secCrit.setMaxResults(maxResults);
return secCrit.list();


It fires a query for fetching these details but the query includes Join to SystemInUse table as well.
I am now confused on how to use setFetchMode of Criteria.
Is there any way I can achieve this as the number of records is high and I cannot have the n queries model here?
Thanks
Monika


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.