-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to get only parent object's data without child object.
PostPosted: Tue Feb 07, 2012 2:07 pm 
Newbie

Joined: Tue Feb 07, 2012 2:04 pm
Posts: 1
Hi,

I have relationships like OnetoMany and ManyToOne in one of my class to the other classes.Here my problem is ,when I am trying to save the parent object,I am able to save all the child objects .But ,when I am trying to select parent object ,I am getting the child objects also and the same in reverse manner also.If I want to get only one object depending on my criteria,what should I do.Please help me As soon as Possible.It is required for me to improve the performance of my application.


Top
 Profile  
 
 Post subject: Re: How to get only parent object's data without child object.
PostPosted: Thu Feb 09, 2012 8:51 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
.But ,when I am trying to select parent object, I am getting the child objects also


This depends on how you define the relation, if you define it EAGER or LAZY.

Quote:
If I want to get only one object depending on my criteria,what should I do.


If you have defined a relation EAGER and if regardsless of this,
you want that regarding property is not loaded too (join query) when you execute a query by criteria,
then you must use the FetchMode.SELECT before execting the query.

Code:
Criteria crit =  _nativeSession.createCriteria(MyChild.class);
            crit.add(Restrictions.eq("name",name));
            ...
            crit.setFetchMode("relationParent", org.hibernate.FetchMode.SELECT);


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