History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HHH-2847
Type: Bug Bug
Status: Resolved Resolved
Resolution: Rejected
Priority: Major Major
Assignee: Diego Plentz
Reporter: Ashish Tiwari
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

THIS_"."NAME": invalid identifier when using createCriteria with addOrder

Created: 17/Sep/07 11:44 AM   Updated: 27/Nov/07 03:34 AM
Component/s: query-criteria
Affects Version/s: 3.0.5
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Oracle - 10.2.0


 Description  « Hide
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,


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Diego Plentz - 17/Sep/07 09:50 PM
Already tried with 3.2.5?

Ashish Tiwari - 18/Sep/07 08:45 AM
No. This problem is not reproducible at will. The problem shows up occasionally during our automated tests execution. Automated tests are executed daily and once in a month (sometimes twice) the test fails with similar error. There is no easy way for me to try 3.2.5 unless the version is change for the project. Change in hibernate version would impact entire project. If there is evidence that moving to 3.2.5 would resolve this issue then I can make the proposal for upgrading hibernate. For that I would need information on what has changed that would prevent this issue from happening with 3.2.5. Thanks,

Diego Plentz - 23/Sep/07 04:34 PM
Well, if you cannot reproduce the error, I will close the issue (we cannot solve a problem that we cannot understand). If you provide a *running* test case I will reopen the issue.

Nguyen Hau Giang - 02/Oct/07 02:02 AM
try using keyword "this" in sort property name:

HibernateUtil.getSession().createCriteria(SystemBean.class)
.addOrder(Order.asc("this.name")).list();

Nguyen Hau Giang - 02/Oct/07 05:54 AM
Our system is running in Japanese locale + Hibernate 3.2.4sp1,
and we met exactly the same problem.
In the meantime, I can not create test case to reproduce problem
but if more than 1 man meet the same problem, may be it's a real bug.

mega - 27/Nov/07 03:34 AM
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.