• Post Reply 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Hibernate Criteria help.

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


Could any one help me how to write the below HQL in Hibernate criteria....

Select t1 from table1 t1, table2 t2 where t1.CID= t2.CID and t2.id=val;

here val is input from the user.

Table1 :
CID,
data

Table2:
CID
ID



pls pls pls pls pls

Thanks
Praveen Kumar
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need for the pls pls pls.

The first thing you need is a mind shift. So, you've got tablea and tableb and tablec? How does that matter? I could have one class mapped across all three tables. Or ten-thousand classes mapped to those three tables? You are thinking about tables. Sure, they are the underpinning of your data, but Hibernate and the Criteria API is all about your OBJECTS.

What classes to you have?

TableA and TableB? Maybe a User and an Address? Maybe a Course and Students? What are the OBJECTS?

Then, when you have the objects, you can create your criteria query.

So, a user has an address, and you want to final all Users that live in Toronto? Do this:



Now, do a criteria Example query based on the User. Since the example provided has a city address of Toronto, you'll get back all users that live in Toronto.

What are the names of the underlying tables in this User-Address example, and how many tables are there? Well, there are actually 5000 tables! Yeah, 5000! But we don't care, because that is all mapped behind the scenes by crazy database admins. All we care about is the OBJECTS and their relationships.

Here's an example of some Criteria code, just to give you an idea of how it might work:



If you're interested, you can find more in this tutorial of mine:

Working with the Hibernate Criteria API: Examples and Tutorials

Good luck!

-Cameron McKenzie
[ May 27, 2008: Message edited by: Cameron Wallace McKenzie ]
 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron,

Thanks for your reply.

I mean tables in the sense i have two classes.

Assume that tables are classes....

Could you tell how to write criteria to join the tables/classes
for above issues ?
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic