aspose file tools*
The moose likes Object Relational Mapping and the fly likes new to hibernate, spring.. criteria queries/joins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply locked New topic
Author

new to hibernate, spring.. criteria queries/joins

Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
I am trying to figure out how to join tables using criteria. I have successfully been able to get records out of one table and pared down the results using Projections.

We have a table called listing that contains a bunch of records. they are joined to another table called pagers. there is a one to many relationship from listing to pagers (one listing record may have multiple pagers associated with it). the main issue I am having is retrieving any data out of the pager table. I think I have the associationPath wrong, which is where I am having problems. There aren't many good examples out on the web doing this kind of a thing and the Cat/kittens examples from the hibernate docs aren't helping.

Here is the criteria query I am using (I am passing in a name and if :


Thanks in advance for any help you can give to me! Let me know if you need any more info.
Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
alright.. let me rephrase this question using the examples from the hibernate documentation. since the documentation always talks about joining a table to itself using the cats/kittens analogy I'll use that as an example but move up one step to an owner of a cat/kittens that also owns dogs/puppies.


table: owner
------------
ownerId (pk)
ownerName

table: cat
------------
catID (pk)
ownerId (fk)
catName

table: dog
--------------
dogId (pk)
ownerId (fk)
dogName


Inside the owner hbm file would be two propertieslike this:

How would one join these tables? Here is what I have come up with so far (passing in the ownerId to the function):



for some reason this is bringing back an empty result set.
Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
I've looked at the sql that is generated and it prints out that it is doing an inner join. I am trying to do an outer join. After doing some research it appears that createAlias means no outer join.

My question now is this; how does one do an outer join using criteria? I tried to use setFetchMode("catsOwned",FetchMode.JOIN) but that is still doing an inner join.
Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
Also.. if I remove the createAlias and try to set a projection using catsOwned.catName I get a
Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
check out these links:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1162
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1276

there is a fix for this problem but i don't know if it has been included in latests releases (currently i am working with hibernate 2.1 :-( )


pascal
Jon baso
Greenhorn

Joined: Nov 13, 2006
Posts: 8
Thanks for the links!!
JayPrakash Dutta
Greenhorn

Joined: Jun 23, 2009
Posts: 5
Hi ,
Can any one help me an execution this query having JOIN using DetachedCriteria .
There two diffrent Table.
1) pinterface
2) snmpinterface

String query = "select snmpinterface.ipaddr, snmpinterface.snmpifdescr, snmpinterface.snmpifspeed, snmpinterface.snmpifindex, snmpinterface.snmpifname, snmpinterface.snmpphysaddr from ipinterface, snmpinterface where ipinterface.ismanaged='M' and snmpinterface.nodeid = ipinterface.nodeid and snmpinterface.snmpifindex = ipinterface.ifindex and snmpinterface.nodeid = '" +routerName +"'";

1) devices
2) categories

String query = "select deviceID, advnet_deviceName, CI_ID, CustomerId from devices , categories where devices.isActive = 1 and categories.categoryName='Router' and devices.subCategory = categories.id and domain_manager_id = "+domainManagerID;


Thanks in advance for any help you can give to me.I am waiting your reply..

Thanks
Jay

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to hibernate, spring.. criteria queries/joins
 
Similar Threads
Quering on multiple tables using criteria api
Retrieve collections using projections
ProjectionList hibernate Criteria
Difference in HQL and Criteria
hibernate joining two tables