-->
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.  [ 1 post ] 
Author Message
 Post subject: Joining 4 tables
PostPosted: Mon Apr 18, 2011 11:21 am 
Newbie

Joined: Mon Apr 18, 2011 11:13 am
Posts: 1
I am trying to create a criteria that will take data across 4 tables.
The hibernate classes linked to the tables and their variables linked to the columns are.

Alpha
ala
alb
beid <

Beta
bea
id <
gammaid<

Gamma
gaa
gab
id<
deltaid<

Delta
dea
deb
id<

The < mark the primary/ forign keys

I can manage to get data across 3 tables, the code below takes the value ala from Alpha, bea from Beta and gab from Gamma where Gamma gaa equals the value of variableVal. The code below works ok for this. Alpha and gamma have lower case letters because inside the Beta class they are given lower case letters.

Criteria criteria2 = session.createCriteria(Beta.class,”be”)
.createAlias(“alpha”,”al”)
.createAlias(“gamma”,”ga”)
.setProjection(projections.projecctionList()
.add(Projections.property(“al.ala”))
.add(Projections.property(“be.bea”))
.add(Projections.property(“ga.gaa”))
)
.add(Restrictions.eq(“ga.gab”,varibleVal));

Now I want to get values across 4 tables.
To take the value ala from Alpha, bea from Beta, gaa from Gamma and dea from delta where Gamma gab equals the value of variableVal and Delta dea equals the value variableVal2. I thought that I could add the extra alias and the new projection and restriction as below but this does not work. Hope my question is clear. Thanks for any help regarding this.

Criteria criteria2 = session.createCriteria(Beta.class,”be”)
.createAlias(“alpha”,”al”)
.createAlias(“gamma”,”ga”)
.createAlias(“delta”,”de”)
.setProjection(projections.projectionList()
.add(Projections.property(“al.ala”))
.add(Projections.property(“be.bea”))
.add(Projections.property(“ga.gab”))
.add(Projections.property(“de.dea”))
)
.add(Restrictions.eq(“ga.gab”,varibleVal))
.add(Restrictions.eq(“de.dea”,varibleVal2));
.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.