Summary
In Hibernate, I am trying to LEFT JOIN FETCH properties from subclasses of the main class, where several subclasses have properties with the same name. Hibernation, however, retrieves only the first related objects of the subclass, not the others.
Background
I model genomic features (genes, transcripts and exons) and genetic variants in a hibernate-based system. Genes, transcripts, and exons are all subclasses of GenomicFeature, and each of them can have zero to many GenomicFeatures. Genes, in turn, have transcripts from zero to many — like Exons — and transcripts have zero to many genes and exons. Each of these relationships happens lazily. Sometimes, however, I want to get a variant and all its genomic features, as well as all the genomic functions associated with the immediate genomic features. For example, I want to get a specific variant: Genes / Transcripts / Exons associated with the variant, all gene transcripts, all Genes & Exons transcripts and all Exons transcripts.
Problem
When I make a request for the above, it works, except that Transcripts for the Genes are not retrieved, only Exon Transcripts are retrieved. I assume that this is because the property - gene.transcripts and exon.transcripts - has the same name.
What i tried
Main request in PagingAndSortingRepository below
@Query("SELECT v FROM Variant v" + " LEFT JOIN FETCH v.variantGenomicFeatures AS vgf" + " LEFT JOIN FETCH vgf.genomicFeature AS gf LEFT JOIN FETCH gf.genes LEFT JOIN FETCH gf.exons LEFT JOIN FETCH gf.transcripts" + " WHERE" + " v.id = (:id)") public Variant findOneByIdAndGenomicFeaturesEagerly(@Param("id") Integer id);
I tried combining genomicFeature twice, once for Genes and once for Transcripts & Exons, but this does not work.
I tried only selecting Genes ( WHERE TYPE(gf) = Gene ), but looking at the query that it generates, it still only joins Excon Transcripts and then returns Genes.
java hibernate
Luke g
source share