Hello. I have the following problem. When I execute a criteria, hibernate try to execute this sql sentence:
select
organizati0_.`pk` as pk1_164_0_,
organizati0_.`name` as name2_164_0_,
organizati0_.`Organization_type` as Organiza3_164_0_,
organizati0_.`Organization_parent` as Organiza4_164_0_,
organizati0_.clazz_ as clazz_0_
from
( select
Organization_parent,
name,
pk,
Organization_type,
0 as clazz_
from
`Organization`
union
select
Organization_parent,
name,
pk,
Organization_type,
1 as clazz_
from
`SalesOrg`
) organizati0_
where
organizati0_.`pk`=?
But, the Sun Application Server 8.1 shows me this exception:
Caused by: java.sql.SQLException: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select Organization_parent, name, pk, Organization_type, 0 as c
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
After I see this exception, I thought that the problem was in the subquery: " select Organization_parent, ". It did not have quotation marks. I looked for the class that generate this subquery (hibernate 3.1.3). I saw that org.hibernate.persister.entity.UnionSubclassEntityPersister.java had a method generateSubquery() that does this work. I modified the line 373 with this code:
// buf.append( col.getName() );
buf.append(col.getQuotedName(getFactory().getDialect()));
Now, the criteria executes correctly. I would want to know if this situation is a bug or it is my fault. Thanks.
|