Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0
I have the following problem:
have three classes with many-to-many association with each other.:
[b]Mapping documents:
MessengerRNA.hbm
<set name="proteinCollection" table="MRNA_PROTEIN" lazy="true">
<cache usage="read-write" />
<key column="MRNA_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.Protein" column="PROTEIN_ID" />
</set>
<set name="geneCollection" table="GENE_MRNA" lazy="true">
<cache usage="read-write" />
<key column="MRNA_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.Gene" column="GENE_ID" />
</set>
Protein.hbm
<set name="messengerRNACollection" table="MRNA_PROTEIN" lazy="true">
<cache usage="read-write" />
<key column="PROTEIN_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.MessengerRNA" column="MRNA_ID" />
</set>
<set name="geneCollection" table="PROTEIN_GENE" lazy="true">
<cache usage="read-write" />
<key column="PROTEIN_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.Gene" column="GENE_ID" />
</set>
Gene.hbm
<set name="messengerRNACollection" table="GENE_MRNA" lazy="true">
<cache usage="read-write" />
<key column="GENE_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.MessengerRNA" column="MRNA_ID" />
</set>
<set name="proteinCollection" table="PROTEIN_GENE" lazy="true">
<cache usage="read-write" />
<key column="GENE_ID" />
<many-to-many class="edu.wustl.geneconnect.domain.Protein" column="PROTEIN_ID" />
</set>
the HQL I fired is :
From edu.wustl.geneconnect.domain.Protein as xxTargetAliasxx
where xxTargetAliasxx.messengerRNACollection.id in (
select id From edu.wustl.geneconnect.domain.MessengerRNA where
geneCollection.id in (select id From edu.wustl.geneconnect.domain.Gene where unigeneClusterId = 'Hs.326035' AND ensemblGeneId = 'ENSG00000120738') AND ( refseqId = 'NM_001964' AND ensemblTranscriptId = 'ENST00000239938' ) )
The generated SQL (show_sql=true):
select * from ( select protein0_.PROTEIN_ID as PROTEIN1_, protein0_.ENSEMBL_PEPTIDE_ID as ENSEMBL2_6_, protein0_.REFSEQ_PROTEIN_ID as REFSEQ3_6_, protein0_.UNIPROTKB_ACCESSION
as UNIPROTKB4_6_, protein0_.GENEBANK_PROTEIN_ACCESSION as GENEBANK5_6_, (select 1 from dual) as formula6_,
(select 1 from dual) as formula7_, (select 1 from dual) as formula8_, (select 1 from dual) as formula9_
from PROTEIN protein0_, MRNA messengerr2_, MRNA_PROTEIN messengerr1_
where protein0_.PROTEIN_ID=messengerr1_.PROTEIN_ID and
messengerr1_.MRNA_ID=messengerr2_.MRNA_ID and
(messengerr2_.MRNA_ID in (select messengerr3_.MRNA_ID from MRNA messengerr3_ where
(
messengerr3_.MRNA_ID in
(select gene4_.GENE_ID from GENE gene4_ where gene4_.UNIGENE_CLUSTER_ID='Hs.326035' and gene4_.ENSEMBL_GENE_ID='ENSG00000120738')
)
and messengerr3_.REFSEQ_MRNA_ID='NM_001964' and messengerr3_.ENSEMBL_TRANSCRIPT_ID='ENST00000239938')) )
In generated SQL you will see that lin ktable GENE_MRNA is missing.
--messengerr3_.MRNA_ID in (select gene4_.GENE_ID---