File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Hibernate Criteria help.

 
Praveen Kumar
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic