Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : Amit
Title :
ways create Hibernate SessionFactory
Description :
Example More...
|
Written By : Amit
Title :
Spring Hibernate Integration example
Description :
Example More...
|
Written By : Amit
Title :
ORM Hibernate Best FIT
Description :
Discussion More...
|
Written By : Amit
Title :
One to Many mapping example
Description :
Code More...
|
Written By : Amit
Title :
Many to Many Mapping Example
Description :
code More...
|
Written By : Amit
Title :
Interview questions answer
Description :
discussion More...
|
Written By : Amit
Title :
Interceptor use log SQL statements
Description :
example code More...
|
Written By : Amit
Title :
Class Hierarchy Persist example
Description :
code More...
|
| Tags/Keywords : Hibernate Criteria, Hibernate Query, Hibernate, Example, Code, Tutorial, Article Author : Amit Date (Year/Month/Date): 2009-05-25
Question on Hibernate Criteria
Suppose there is a one to many mapping between person and role.
While quering Person based on certain role, if a filter criteria
is required based on role only, Is there any ways one can do
such mapping with some filter criteria??
Or any other ways of doing Hibernate Query criteria on dependent
objects??
Let me discuss this scenario with this example,
A person can have many roles such as Manager,
Assistant manager, general manager, secretary,
Architect etc.
So when this person object is queried, then
roles to be queried should have Manager roles only,
like Manager, Assistant manager, general manager
and not Secretary and Achitect.
One way it can be by providing a Hibernate named query
and other way could be by creating Hibernate Criteria
and providing appropriate Restrictions in Java code.
Can someone take this as a task and complete this
example with a very simple example on Hibernate Criteria
and publish this Hibernate Criteria example in this Page?
As we are discussing about using filters with Hibernate Entities, then one can
look more towards the Hibernate Filters, such as <filter-def> Tag in Hibernate
mapping file. It can be used along with a class Tag and/or with collection
tags as well.
This <filter-def> tag can use parameters begining with : and these parameters
can be used in code to set values. Session has method enableFilter(FILTER_NAME) to
get Filter object. All parameters value can be set on this Filter object, in order to
provide a filter criteria to the mapping.
To the best of my understanding, using Hibernate to form query based on certain filter
criterias, one can use Hibernate Session api, methods like
createCriteria(ENTITY_NAME) to get a Criteria, and work with Restrictions to come up with
query filter requirements
createQuery(QUERY_NAME) to get a Query and work to set appropriate values to parameters
and then executeUpdate or list all the results of this query.
getNamedQuery(QUERY_NAME) to get Query as defined in HBM mapping file, to be executed
to retrieve appropriate values from Resultset.
| |