-->
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: Query by example fetching strategy
PostPosted: Wed Aug 10, 2005 9:12 am 
Newbie

Joined: Mon Aug 08, 2005 11:19 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I'm using the Criteria Query by Example to retrieve a list of parent objects that satisfy search criteria on both parent properties and child properties.

This is actually working using the code below.

However the actual query is bringing back both the parents (headers) and children (samples) - which is more data than I need.

I really only need the header data at this stage.

If I was to write the query myself it would look like....

select h.*
from header h
inner join sample s
on h.id = s.headerID
where h.property like '%c'
and s.property like '%s'


You can see that the query below is fetching more data than necessary and also doing an extra join on the header table.

Can anyone suggest if it is possible to restrict the sample columns from being retrieved.

Many thanks




Hibernate version: 3.05



Code between sessionFactory.openSession() and session.close():

Code:
reports = session.createCriteria(MatchReportHeader.class, "header")
                                        .add( Example.create(exampleHeader)
                                                     .excludeProperty("processedFlag")
                                                     .excludeZeroes()
                                                     .enableLike(MatchMode.ANYWHERE) )
                                        .createCriteria("samples", "s")
                                        .add( Example.create( exampleSample)
                                                          .excludeZeroes()
                                                          .enableLike(MatchMode.ANYWHERE) )
                                        .setFetchMode("samples", FetchMode.DEFAULT)
                                        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
                                        .list();



Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Code:
select this_.id as id2_, this_.version as version0_2_, ......
, s1_.id as id0_, s1_.version as version4_0_, .....
, matchrepor4_.id as id1_, matchrepor4_.version as version0_1_, .....

from matchReportHeader this_
inner join matchReportSample s1_
on this_.id=s1_.headerID
left outer join matchReportHeader matchrepor4_
on s1_.headerID=matchrepor4_.id
where (1=1) and (s1_.exhibitNo like ?)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 5:19 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
Section 12. Criteria Queries states: ... criteria queries do not support projection or aggregation.


In 3.1 you can use the Projections factory and setProjection.


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.