DetachedCriteria with Projections generates invalid SQL when using inheritance with
PostgreSQL
----------------------------------------------------------------------------------------------
Key: HHH-4069
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4069
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6 GA with annotations, PostgreSQL 8.3, Ubuntu Linux
Reporter: Gajo Csaba
Attachments: postgretest.zip
PostgreSQL doesn't allow using aliases in the WHERE clause. For example, the following
query is invalid:
SELECT it.id_item as aaa FROM Item it WHERE aaa=1
The correct query would be:
SELECT it.id_item as aaa FROM Item it WHERE it.id_item=1
When having inheritance with a TABLE_PER_CLASS strategy, the HSQL query "select
idItem from Item where idItem=:idItem" will generate the correct query. However,
doing the same with a DetachedCriteria will generate the invalid query. Note that I'm
not selecting everything from Item. It's not select *. I'm only selecting idItem,
which means in the DetachedCriteria I'm using Projections. Without projections, the
generated query works fine.
I've attached a test case, and the following is a short explanation:
model.Item - abstract superclass
model.Product - extends Item
model.Project - extends Item
Main is the main class. Removing the following piece of code will make the test case work
without errors:
criteria.setProjection(Projections.projectionList()
.add(Projections.property("idItem"), "idItem")
.add(Projections.property("name"), "name"));
The test case may be compiled with Maven.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira