-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Quotes in subquery
PostPosted: Thu Apr 27, 2006 8:28 am 
Newbie

Joined: Tue Apr 25, 2006 4:29 am
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.