goashok / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Can we use Join in search functionality #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

 I have objects mapped with many-to-one relationship, when i use the search
() method, i see separate SQLs were fired on databse for each objcet, 
Instead I want to use Join, can you please advice.

Eg: I have table Mobile has many-to-one relation with Location and 
Provider tables. when I tried to get location and provider information 
from Mobile using lazy="flase" and fetch="join", still I see three sqls 
firing.
HibernateSQL1: select mobile0_.MSC_ID as MSC1_1_, mobile0_.RANGE_FROM as 
RANGE2_1_, mobile0_.RANGE_TO as RANGE3_1_, mobile0_.LOCATION_ID as 
LOCATION4_1_, mobile0_.PROVIDER_ID as PROVIDER5_1_ from 
hibernatedb.MSC_CODES mobile0_ where mobile0_.RANGE_FROM>=? and 
mobile0_.RANGE_TO<=?

HibernateSQL2: select location0_.LOCATION_ID as LOCATION1_2_0_, 
location0_.LOCATION_CODE as LOCATION2_2_0_, location0_.LOCATION_NAME as 
LOCATION3_2_0_ from hibernatedb.LOCATION location0_ where 
location0_.LOCATION_ID=?

HibernateSQL3: select provider0_.PROVIDER_ID as PROVIDER1_3_0_, 
provider0_.PROVIDER_CODE as PROVIDER2_3_0_, provider0_.PROVIDER_NAME as 
PROVIDER3_3_0_ from hibernatedb.PROVIDER provider0_ where 
provider0_.PROVIDER_ID=?

instead I want to use join between three tables.

Original issue reported on code.google.com by iits...@gmail.com on 14 May 2009 at 4:21

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Please post this on the google group:
http://groups.google.com/group/java-generic-dao?pli=1

Original comment by dwolvert on 14 May 2009 at 7:50

GoogleCodeExporter commented 9 years ago
Have you tried search.addFetch("location").addFetch("provider")? If that 
doesn't 
work, then Hibernate probably can't do what you when executing a query. If you 
find 
that you can do it with hibernate, but you cannot do it with this search, 
please let 
me know how it is done so I can make improvements.

Original comment by dwolvert on 14 May 2009 at 7:57

GoogleCodeExporter commented 9 years ago
Thanks for information, addFetch is working.

Original comment by iits...@gmail.com on 15 May 2009 at 2:34

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 20 May 2009 at 4:09