[Hibernate-JIRA] Created: (HHH-2376) Query with fully qualified entity class fails
by Neukomm (JIRA)
Query with fully qualified entity class fails
---------------------------------------------
Key: HHH-2376
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2376
Project: Hibernate3
Type: Bug
Components: query-hql
Versions: 3.2.1
Environment: Hibernate 3.2.1ga, HSQLDB 1.8.0.4
Reporter: Neukomm
Attachments: DiscriminatorTest2.java
We've recently ran into a problem while migrating from Hibernate 3.1.1 to Hibernate 3.2.1ga:
While queries against the class attribute still work, if the class is non-qualified, the query fails if the
name is fully qualified.
e.g.
"from Person p where p.class = Person"
works fine while
"from Person p where p.class = org.hibernate.test.discriminator.Person"
fails.
I've attached a test case to illustrated the problem. It should work when it's put into the
'discriminator' package of the hibernate junit test cases.
Both testcases work fine for hibernate versions up to and including 3.2.0cr2.
In later versions, specifically in 3.2.1ga, the test case that uses the fully qualified class name
('testQueryWithPackage') fails.
--
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
17 years, 10 months
[Hibernate-JIRA] Commented: (HHH-817) using projections is causing SQL query error on oracle (ORA-00904 error)
by Michal Palicka (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
Michal Palicka commented on HHH-817:
------------------------------------
Hello!
The query generated by Hibernate is definitely an invalid SQL, since column aliases are not allowed in WHERE clauses.
SQL evaluates the statements in the following order:
(1) the FROM clause
(2) the WHERE clause
(3) the SELECT clause
When the WHERE clause is being evaluated, the aliases from the SELECT clause are not yet known.
There are several links that describe the problem:
http://www.sqlhacks.com/index.php/Retrieve/Alias-in-where
http://archives.postgresql.org/pgsql-general/2002-11/msg01411.php
http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html
I do not have the SQL standard specification at hand, but the third document (at mysql.com) states
that the mentioned behaviour is part of the SQL standard (so it is not a bug in Oracle, Postgres or MySQL).
Please, change the priority of this issue to "Critical".
Thank you.
> using projections is causing SQL query error on oracle (ORA-00904 error)
> ------------------------------------------------------------------------
>
> Key: HHH-817
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
> Project: Hibernate3
> Type: Bug
> Versions: 3.0.5
> Environment: Oracle 9.2.0.6, Hibernate 3.0.5, Spring Framework 1.2.2 based application working on Jakarta Tomcat 5.0.28
> Reporter: Michal Jastak
> Priority: Minor
>
>
> following java code:
> protected Entity loadEntityLightweight(Serializable entityId) throws DataAccessException {
> Criteria criteria = getSession().createCriteria(Entity.class);
> ProjectionList projectionList = Projections.projectionList();
> projectionList.add(Property.forName(BaseEntity.PROP_ID), BaseEntity.PROP_ID);
> projectionList.add(Property.forName(BaseEntity.PROP_TYPE), BaseEntity.PROP_TYPE);
> criteria.setProjection(projectionList);
> criteria.add(Restrictions.eq(BaseEntity.PROP_ID, entityId));
> criteria.setResultTransformer(new AliasToBeanResultTransformer(Entity.class));
> return (Entity) criteria.uniqueResult();
> }
> generates following SQL query:
> select this_.id as y0_, this_.type as y1_ from entities this_ left outer join facilities this_1_ on this_.id=this_1_.id left outer join users this_2_ on this_.id=this_2_.id left outer join addresses address2_ on this_.address_id=address2_.id left outer join entities entity3_ on this_2_.employer_id=entity3_.id left outer join facilities entity3_1_ on entity3_.id=entity3_1_.id left outer join users entity3_2_ on entity3_.id=entity3_2_.id where y0_=?
> y0_ = ? expression in where clause is causing a 904 error on Oracle 9:
> ORA-00904: "Y0_": invalid identifier
> hibernate dialect: org.hibernate.dialect.Oracle9Dialect
> mapping for Entity class:
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> <hibernate-mapping default-lazy="false" default-cascade="save-update">
>
> <class name="Entity" table="entities" mutable="true">
> <id name="id" type="java.lang.Long" unsaved-value="null">
> <generator class="sequence">
> <param name="sequence">entities_id_seq</param>
> </generator>
> </id>
> <many-to-one name="address" class="Address" column="address_id" />
> ...
> <!--
> - Facilities
> -->
> <joined-subclass name="Facility" table="facilities">
> <key column="id" />
> ...
> <set name="users" inverse="true" lazy="true">
> <key column="facility_id" />
> <one-to-many class="User" />
> </set>
> </joined-subclass>
> <!--
> - Users
> -->
> <joined-subclass name="User" table="users" dynamic-insert="true" dynamic-update="true">
> <key column="id" />
> <many-to-one name="employer" class="Entity" column="employer_id" cascade="none" />
> ...
> <set name="userAuthorities" inverse="true" cascade="all-delete-orphan">
> <key column="user_id" />
> <one-to-many class="Authority" />
> </set>
> </joined-subclass>
> </class>
> </hibernate-mapping>
--
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
17 years, 10 months