[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2847) THIS_"."NAME": invalid identifier when using createCriteria with addOrder
mega (JIRA)
noreply at atlassian.com
Tue Nov 27 04:34:57 EST 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28965 ]
mega commented on HHH-2847:
---------------------------
I met the same problem.
I use 3.2.4.sp1, oracle 10g.
As i know, let's the reason of the problem occurs.
Using Criteria for query, if you apply a Projection to a query, then use Restrictions to narrow the result set, and the defined Projection property same as the defined Restrictions property, the sql generated by hibernate will have the wrong alias. If you don't apply Projections, no problem.
Here is the code:
Criteria criteria = createCriteria(Project.class);
1. criteria.setProjection(Projections.projectionList().add(Projections.property("name"), "name"));
2. criteria.add(Restrictions.like("name", "ttilyf", MatchMode.ANYWHERE));
criteria.addOrder(Order.desc("id"));
criteria.list();
sql:
select this_.name as y0_ from project this_ where y0_ like ? and 1=1 order by this_.id desc
error info:
ORA-00904: y0_: invalid identifier
And if remove line 1 or 2, that ok.
Now change line 1 to
criteria.setProjection(Projections.projectionList().add(Projections.property("name")); or
criteria.setProjection(Projections.projectionList().add(Projections.property("name"), "alias_name"));
it's ok.
sql:
select this_.name as y0_ from project this_ where this_.name like ? and 1=1 order by this_.id desc
Now, i think everyone know how to avoid this problem.
ps:sorry for my suck english.
> THIS_"."NAME": invalid identifier when using createCriteria with addOrder
> -------------------------------------------------------------------------
>
> Key: HHH-2847
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2847
> Project: Hibernate3
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.0.5
> Environment: Oracle - 10.2.0
> Reporter: Ashish Tiwari
> Assignee: Diego Pires Plentz
>
> We are using hibernate 3.0.5 and once a while I see following error getting generated due to incorrect SQL generated by hibernate:
> Hibernate: select systembean0_.SYSTEMID as SYSTEMID12_0_, systembean0_.Version as Version12_0_, systembean0_.NAME as NAME12_0_, systembean0_.TYPE as TYPE12_0_, systembean0_.DESCRIPTION as DESCRIPT5_12_0_ from SDSYSTEM systembean0_ order by this_.NAME asc
> - SQL Error: 904, SQLState: 42000
> - ORA-00904: "THIS_"."NAME": invalid identifier
> This normally works but occasionally we run into the issue mentioned above. I do not see alias "this_" in the sql query and I think that causes the error to happen. Issue is caused by alias not used consistently.
> In normal case the generated SQL looks like following:
> Hibernate: select this_.SYSTEMID as SYSTEMID7_0_, this_.Version as Version7_0_, this_.NAME as NAME7_0_, this_.TYPE as TYPE7_0_, this_.DESCRIPTION as DESCRIPT5_7_0_ from SDSYSTEM this_ order by this_.NAME asc
>
> I am not sure what causes this problem. Has anyone else see similar problem earlier?
> I appreciate any help with this. Below is other information:
> Hibernate version: 3.0.5
> Mapping documents:
> <?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>
> <class
> name="com.avaya.coreservice.admin.toolkit.common.system.SystemBean"
> table="SDSYSTEM">
> <id name="uniqueId" type="java.lang.String">
> <column name="SYSTEMID" length="50" not-null="true"/>
> <generator class="uuid"/>
> </id>
> <version name="version" column="Version" />
> <property
> name="name"
> type="java.lang.String">
> <column name="NAME" length="512" not-null="true"/>
> </property>
> <property
> name="type"
> type="java.lang.String">
> <column name="TYPE" length="50" not-null="false"/>
> </property>
> <property
> name="description"
> type="java.lang.String">
> <column name="DESCRIPTION" length="1024" not-null="false"/>
> </property>
> <set name="resourceBeanSet">
> <key>
> <column name="SYSTEMID" length="50" not-null="false"/>
> </key>
> <one-to-many class="com.avaya.coreservice.admin.toolkit.common.resource.ResourceBean"/>
> </set>
> <set name="siteBeanSet" order-by="name asc">
> <key>
> <column name="SYSTEMID" length="50" not-null="false"/>
> </key>
> <one-to-many class="com.avaya.coreservice.admin.toolkit.common.site.SiteBean"/>
> </set>
> </class>
> </hibernate-mapping>
> Code between sessionFactory.openSession() and session.close():
> HibernateUtil.getSession().createCriteria(SystemBean.class)
> .addOrder(Order.asc("name")).list();
> Full stack trace of any exception that occurs:
> N/A
> Name and version of the database you are using:
> Oracle - 10.2.0
> The generated SQL (show_sql=true):
> select systembean0_.SYSTEMID as SYSTEMID12_0_, systembean0_.Version as Version12_0_, systembean0_.NAME as NAME12_0_, systembean0_.TYPE as TYPE12_0_, systembean0_.DESCRIPTION as DESCRIPT5_12_0_ from SDSYSTEM systembean0_ order by this_.NAME asc
> I appreciate any help with this.
> Thanks,
--
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list