Rakesh,
The type of SQL query you are describing in your example, is a theta-style query. This means that the relationship between tables is achieved not via a JOIN clause, but by specifying equal field values in the WHERE clause.
The normal thing to do in Hibernate, would be to map your Employee and Department classes to database tables, and to indicate (via annotations or configuration files) which one is a collection contained on instances on the other. In your example, we can assume that a Department has many employees.
Hibernate uses that information in order to build SQL joins internally. In a Criteria, you start with one specific class, and then attach code for the other, building on that SQL JOIN clause that Hibernate had already figured out, based on your configuration.
That's why your question doesn't really make much sense. If you have no one-to-many relationships (i.e. no joins) defined in your configuration, and that is the reason you have to use a theta-style join, then it doesn't make sense to use a Criteria.
|