[hibernate-issues] [Hibernate-JIRA] Commented: (HB-281) ".class" with <joined-subclass> problem

Steve Ebersole (JIRA) noreply at atlassian.com
Thu Nov 16 12:08:05 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HB-281?page=comments#action_25343 ] 

Steve Ebersole commented on HB-281:
-----------------------------------

Unfortunately the issue is much more insidious and much more complex than just that.  True, the JoinSequence.Selector applied during JoinProcessor.processJoins() is wrong, but it is wrong because it does not have all the info it needs at that time.  I actually already have this fixed (well the HHH version, as this will obviously not be getting backported to Hibernate2) on my local box in regards to both .class and general sub/super-class property references...

> ".class" with <joined-subclass> problem
> ---------------------------------------
>
>          Key: HB-281
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HB-281
>      Project: Hibernate2
>         Type: Bug

>   Components: core
>  Environment: windows 2000
>     Reporter: Simone Ricciardi
>     Priority: Minor

>
>
> 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 )

-- 
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