-->
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.  [ 4 posts ] 
Author Message
 Post subject: inner join (MORE THANT 3 TABLES) WITH CRITERIA
PostPosted: Thu Sep 29, 2005 10:20 am 
Newbie

Joined: Thu Sep 29, 2005 9:54 am
Posts: 4
I'm using the last version of Hibernate i think 3.1..
By having lazy=true in all may asosciation I have to create a an inner join between several tables in order to upload all the info from the db when needed.


I have a table A which have a one to one relation with tables B and C.
Then i have a one to many relation between B and E, the same association (one to many) between C and F.

I have to following code :
session.createCriteria(A.class)
.createCriteria("B","BObject")
.createCriteria("BObject.E")
Long(bomId))).uniqueResult();

This is working perfectly and i can see the inner join sql from the sql output on server..every thing is perfect.
The output for this is :

select count(*)
From A ATable,
B_E B_ETable,
E ETable,
Where A_id = 'something'
and A.A_id = B_ETable.B_id
and B_ETable.B_id = ETable.E_id


But as soon as i try to incorporate
.createCriteria("C","CObject")
.createCriteria("CObject.F") befor the unqiueResult() method i have a null pointer exception That means this is not working :

session.createCriteria(A.class)
.createCriteria("B","BObject")
.createCriteria("BObject.E")
.createCriteria("C","CObject")
.createCriteria("CObject.F")
Long(bomId))).uniqueResult();


I'm prety much new to Hibernate API...
What i whant is to have thic query :

select count(*)
From A ATable,
B_E B_ETable,
E ETable,
C_F C_FTable
Where A_id = 'something'
and A.A_id = B_ETable.B_id
and A.A_id = C_FTable.C_id
and B_ETable.B_id = ETable.E_id
and C_FTable.C_id = ETable.E_id

B_E and C_F tables are the jonctions tables between the one to many unidirectional relationship between B-E and C-F

Could some body help me...i spend lot of time and i just can't get the write way for this.

Thanks for your help

vahed


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 11:00 am 
Newbie

Joined: Thu Sep 29, 2005 9:54 am
Posts: 4
ok the verison of Hibernate that i'm using is 3.0


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 11:27 am 
Newbie

Joined: Thu Sep 29, 2005 9:54 am
Posts: 4
ok i have resolve the porblem to get the sql query that i whant with the followin code :

session.createCriteria(A.class)
.createAlias("B","ObjectB")
.createAlias("ObjectB.E","EObject")
.createAlias("C","ObjectC")
.createAlias("ObjectC.F","ObjectF")
.createCriteria("EObject")
.createCriteria("FObject")
.add( Restrictions.idEq(new Long(bomId))).uniqueResult();
}
i still get the java null pointer exception


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 11:58 am 
Newbie

Joined: Thu Sep 29, 2005 9:54 am
Posts: 4
Ok is have exmined the query well and i get the following problem

I have "and " operator ever where in my query :

The relationship between my tables are (A,B,C,E anf F):

- A could be linked to B which would be linked to E
- A could be linked to C which would be linked to F

With and every where the could become must.

Could some body help me


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

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.