I am trying to resolve a bug in my system, related to pagination. When a user selects a record, we retrieve all the associated records back to the user using pagination.
With the page maxResults set, the DB retrieves the max records but they are duplicated and returned to hibernate. Hibernate then retrieves the duplicates and returns the remaining records back to the UI. this causes inconsistency between the number of records returned vs page max size.
Using hibernate and criteria queries, this is the SQL that gets executed which retrieves all the associated records.
select
this_.id ,
this_.created_date ,
this_.is_reanalysis_user ,
this_.library ,
this_.state ,
this_.compare_category_id ,
this_.chipkit_id ,
this_.librarykit_id ,
this_.sequencingkit_id ,
this_.templatekit_id ,
this_.templateType ,
ucc.id ,
usrp.user_id ,
usrp.run_parameter_id ,
user1.id ,
user1.templateType ,
utt.VALUE ,
urp.id ,
uki.id as id1_214_5_,
uki.unique_name ,
uki1.id ,
uki1.unique_name ,
ukart.KIT_ID ,
uart.RUN_TYPE ,
uart.RUN_TYPE ,
uki2.id ,
uki2.unique_name ,
uki3.id ,
uki3.unique_name ,
utt.VALUE ,
from
USER this_
left outer join
USER_compare_category ucc
on this_.compare_category_id=ucc.id
inner join
USER_SAVED_RUN_PARAMETER usrp
on this_.id=usrp.user_id
left outer join
USER user1
on usrp.user_id=user1.id
left outer join
USER_TEMPLATE_TYPES utt
on user1.templateType=utt.VALUE
left outer join
USER_RUN_PARAMETER urp
on usrp.run_parameter_id=urp.id
inner join
USER_KITINFO uki
on this_.chipkit_id=uki.id
inner join
USER_KITINFO uki1
on this_.librarykit_id=uki1.id
inner join
USER_KIT_ALLOWED_RUN_TYPES ukart
on uki1.id=ukart.KIT_ID
inner join
USER_ALLOWED_RUN_TYPES uart
on ukart.ALLOWED_RUN_TYPE=uart.RUN_TYPE
inner join
USER_KITINFO uki2
on this_.sequencingkit_id=uki2.id
inner join
USER_KITINFO uki3
on this_.templatekit_id=uki3.id
inner join
USER_TEMPLATE_TYPES utt
on this_.templateType=utt.VALUE
where
utt.VALUE in (
'custom', 'install_seq'
)
and this_.is_reanalysis_user=false
and this_.state in (
'Locked', 'Draft'
)
and utt.VALUE<>'install_seq'
and uki.unique_name='Chip-Chock'
**and usrp.value='amplitude_1'**
and uart.RUN_TYPE in (
'sample'
)
and uki1.unique_name='Blane Library Kit'
and utt.VALUE<>'install_seq'
and uki3.unique_name='Moon reagent Kit'
and uki2.unique_name='Star Seq Kit'
order by
this_.created_date desc
limit 5 offset 0
what i have observed is that USER WITH USER_SAVED_RUN_PARAMETER has @OneToMany relationship and thus i see duplicates, I need to somehow add a condition usrp.value='amplitude_1' to select just the first record from this table.
Is there a way to do that? first, i was hoping I can try in SQL and then hibernate criteria query.