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 ?)