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
|