By pradeep_kmrc
via ch-express.blogspot.com
Submitted: Jun 29 2008 / 14:35
The API Documenataion of Hibernate's Criteria API's sqlRestriction method, defines as follows:
/**
* Apply a constraint expressed in SQL, with the given JDBC
* parameter. Any occurrences of {alias} will be replaced
* by the table alias. */
Make note of the {alias} placeholder in the above comments.
The catch is the only {alias} this method understands is the alias name of the root table on which the Criteria call is constructed. If more than one table is joined in the Criteria query either using the createCriteria or the createAlias method, the alias of these 'joined' tables are not understood by the Criteria API.
In order to get over this problem in our project, we had to look at the SQL generated by the Criteria object, figure out the alias name generated by hibernate and then code that in the SQL that is passed in as an argument to the sqlRestriction method.
For example in the below snippet,
Criteria c = session.createCriteria(BaseTable.class, "base");
c.createAlias(SecondTable.class, "second", CriteriaSpecification.LEFT_JOIN);
sqlRestriction method can interpret only "base" as the alias.
Tweet
SaveShareSend
Tags: database, frameworks, java, open source
Add your comment