This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

new to hibernate, spring.. criteria queries/joins

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Also.. if I remove the createAlias and try to set a projection using catsOwned.catName I get a
 
Jon baso
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for the links!!
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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

 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic