|
From: <leg...@at...> - 2003-08-26 14:28:28
|
The following comment has been added to this issue:
Author: Simone Ricciardi
Created: Tue, 26 Aug 2003 9:28 AM
Body:
Unfortunately I've also gotten the same error, when the Query.iterate() is used instead of Query.list(). In this case (and this is more serious) the error also happens when the entity is being returned in the select clause (not only with select count(*)).
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-281
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-281
Summary: ".class" with <joined-subclass> problem
Type: Bug
Status: Unassigned
Priority: Minor
Project: Hibernate2
Components:
core
Assignee:
Reporter: Simone Ricciardi
Created: Fri, 22 Aug 2003 2:38 AM
Updated: Fri, 22 Aug 2003 2:38 AM
Environment: windows 2000
Description:
I've acknowledged an error that happens using "select count (*) ..."
together to a where clause "... where alias.class = ClassName ".
Suppose to have two classes:
public class Foo
{
String id;
String attr1;
public String getId(){ return id; }
public void setId(String id){ this.id = id; }
public String getAttr1(){ return attr1; }
public void setAttr1(String attr1){ this.attr1 = attr1; }
}
public class Bar extends Foo
{
String attr2;
public String getAttr2(){ return attr2; }
public void setAttr2(String attr2){ this.attr2 = attr2; }
}
and the corresponding mapping file:
<hibernate-mapping>
<class name="test.persistents.Foo" table="Foo">
<id name="id" type="string">
<column name="id" length="32"/>
<generator class="uuid.hex"/>
</id>
<property name="attr1" column="attr1" type="string"/>
<joined-subclass name="test.persistents.Bar" table="Bar">
<key column="foo_id"/>
<property name="attr2" column="attr2" type="string"/>
</joined-subclass>
</class>
</hibernate-mapping>
When I try to make the following query:
Query query = session.createQuery("select count(*) from Foo foo where foo.class = Foo");
I get an error of this type:
java.sql.SQLException: General error, message from server: "Unknown table 'foo0__1' in where clause"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1651)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:889)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:956)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1874)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1538)
at com.p6spy.engine.logging.P6LogPreparedStatement.executeQuery(P6LogPreparedStatement.java:171)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:71)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:551)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:140)
at net.sf.hibernate.loader.Loader.find(Loader.java:620)
at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:76)
at test.Test.main(Test.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
while if I perform the same query without the select count(*) (select foo from Foo foo where foo.class = Foo)
all works fine.
Comparing the two queries produced by hibernate in both cases,
it seems that the error derives from the lack of the "left outer join" with the Bar table in the "from" clause:
with select count(*):
select count(*) as x0_0_
from Foo foo0_
where (case when foo0__1.foo_id is not null then 1 when foo0_.id is not null then 0 end=0 )
without select count(*):
select foo0_.id as id,
case when foo0__1.foo_id is not null then 1
when foo0_.id is not null then 0 end
as clazz_,
foo0_.attr1 as attr10_,
foo0__1.attr2 as attr21_
from Foo foo0_ left outer join Bar foo0__1 on foo0_.id=foo0__1.foo_id
where (case when foo0__1.foo_id is not null then 1 when foo0_.id is not null then 0 end=0 )
in fact the query should be the following:
select count(*) as x0_0_
from Foo foo0_ left outer join Bar foo0__1 on foo0_.id=foo0__1.foo_id
where (case when foo0__1.foo_id is not null then 1 when foo0_.id is not null then 0 end=0 )
---------------------------------------------------------------------
JIRA INFORMATION:
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
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|