Details
Description
Before upgrading to 0.9.9, we can create a virtual class in mapping to compose two and more real table. For example:
CALL SQL SELECT a.a1, a.a2, b.b1, b.b2 from tableA a left join tableB b on b.a = a.id AS model.Dummy
It throws the following exception for now on:
java.sql.SQLException: Column index out of range.
at org.exolab.castor.jdo.engine.SQLEngine$SQLQuery.fetchRaw(SQLEngine.java:2561)
at org.exolab.castor.jdo.engine.SQLEngine$SQLQuery.nextIdentity(SQLEngine.java:2249)
at org.exolab.castor.persist.QueryResults.nextIdentity(QueryResults.java:174)
at org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.hasMore(OQLQueryImpl.java:581)
at org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.hasMore(OQLQueryImpl.java:567)
When debugging, I'm surprised to find the SQLEngine use the nonexistent dummy table name in the query statment.
BTW, there is another bug I found before. The following mapping will make query fail:
<class identity="id" name="model.Item">
<map-to table="item"/>
<field name="id" type="integer">
<sql name="id" type="integer"/>
</field>
<field name="prop" type="model.Prop" collection="collection">
<sql many-key="item" />
</field>
<field name="name" type="string">
<sql name="name" type="varchar"/>
</field>
</class>
while, this doesn't:
<class identity="id" name="model.Item">
<map-to table="item"/>
<field name="id" type="integer">
<sql name="id" type="integer"/>
</field>
<field name="name" type="string">
<sql name="name" type="varchar"/>
</field>
<field name="prop" type="model.Prop" collection="collection">
<sql many-key="item" />
</field>
</class>
Someone also comment it out in line 2392, SQLEngine.java:
// TODO: wrong, as it could be that the first field is not part of the root class.
if (numberOfFields > 0) {
tableName = _engine._fields[0].tableName;
Testcase will be attached.
Sean, is there any way you could join me on IRC ? Either connect to irc://irc.codehaus.org:6665/castor, or if you cannot connect due to security restrictions, pleae use http://irc.codehaus.org, and join the castor channel.