-->
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.  [ 4 posts ] 
Author Message
 Post subject: createSQLQuery too buggy.
PostPosted: Wed Oct 22, 2003 8:57 pm 
Newbie

Joined: Wed Oct 22, 2003 3:05 am
Posts: 9
I thought Max said somewhere that the sql queries were run straight through.. if this is so, i don't understand why this simple query below comes out to be such a complicated one (which is exactly like when i do it in HQL translated to sql)

The sql query after you guys get through it, doesn't run on oracle by the way.. it takes forever to parse on Toad and at the end comes back with the same below message.

what are you doing? please explain..


String sqlstr = "select {s.*} from Survey_Indice {s} where ROWNUM < 4 ";
Session session = xxx.xx.xx.xx.SessionFactory.getSession();


Query query = session.createSQLQuery(sqlstr,"s", SurveyIndice.class);

Hibernate: select s.SURVEY_INDICE_ID as SURVEY_INDICE_ID0_, case when s_1_.SURVEY_INDICE_ID is not null then 1 when s_2_.SURVEY_INDICE_ID is not null then 2 when s_3_.SURVEY_INDICE_ID is not null then 3 when s_4_.SURVEY_INDICE_ID is not null then 4 when s_5_.SURVEY_INDICE_ID is not null then 5 when s_6_.SURVEY_INDICE_ID is not null then 6 when s.SURVEY_INDICE_ID is not null then 0 end as clazz_0_, s.DISPLAY_SEQUENCE as DISPLAY_2_0_0_, s.NAME as NAME0_0_, s.CREATE_DT as CREATE_DT0_0_, s.UPDATE_DT as UPDATE_DT0_0_, s.STATUS as STATUS0_0_, s.INDICE_TYPE as INDICE_T7_0_0_, s.SURVEY_ID as SURVEY_ID0_0_, s.PARENT_INDICE_ID as PARENT_I9_0_0_, s.CUSTOMER_ID as CUSTOME10_0_0_, s.CREATE_USER_ID as CREATE_11_0_0_, s.UPDATE_USER_ID as UPDATE_12_0_0_, s_1_.TEXT as TEXT1_0_, s_1_.CUSTOMER_ID as CUSTOMER3_1_0_, s_1_.CREATE_USER_ID as CREATE_U4_1_0_, s_1_.UPDATE_USER_ID as UPDATE_U5_1_0_, s_1_.CREATE_DT as CREATE_DT1_0_, s_1_.UPDATE_DT as UPDATE_DT1_0_, s_2_.TYPE as TYPE2_0_, s_2_.DATATYPE as DATATYPE2_0_, s_2_.TEXT as TEXT2_0_, s_2_.COLUMN_COUNT as COLUMN_C5_2_0_, s_2_.ROW_COUNT as ROW_COUNT2_0_, s_2_.REQUIRED as REQUIRED2_0_, s_2_.ALLOW_OTHER as ALLOW_OT8_2_0_, s_2_.MAX_OTHER_COUNT as MAX_OTHE9_2_0_, s_2_.ALLOW_MULTIPLE as ALLOW_M10_2_0_, s_2_.CUSTOMER_ID as CUSTOME11_2_0_, s_2_.MAXIMUM_CHARS as MAXIMUM12_2_0_, s_2_.MAXIMUM as MAXIMUM2_0_, s_2_.MINIMUM as MINIMUM2_0_, s_2_.DECIMAL_PRECISION as DECIMAL15_2_0_, s_2_.IS_MULTILINE as IS_MULT16_2_0_, s_2_.DATE_FORMAT as DATE_FO17_2_0_, s_2_.CREATE_DT as CREATE_DT2_0_, s_2_.UPDATE_DT as UPDATE_DT2_0_, s_2_.CREATE_USER_ID as CREATE_20_2_0_, s_2_.UPDATE_USER_ID as UPDATE_21_2_0_, s_3_.DESCRIPTION as DESCRIPT2_3_0_, s_3_.CUSTOMER_ID as CUSTOMER3_3_0_, s_3_.CREATE_USER_ID as CREATE_U4_3_0_, s_3_.UPDATE_USER_ID as UPDATE_U5_3_0_, s_3_.CREATE_DT as CREATE_DT3_0_, s_3_.UPDATE_DT as UPDATE_DT3_0_, s_4_.ATTACHMENT as ATTACHMENT4_0_, s_4_.MIME_TYPE as MIME_TYPE4_0_, s_4_.CUSTOMER_ID as CUSTOMER4_4_0_, s_4_.CREATE_USER_ID as CREATE_U5_4_0_, s_4_.UPDATE_USER_ID as UPDATE_U6_4_0_, s_4_.CREATE_DT as CREATE_DT4_0_, s_4_.UPDATE_DT as UPDATE_DT4_0_, s_5_.TEXT as TEXT5_0_, s_5_.CUSTOMER_ID as CUSTOMER3_5_0_, s_5_.CREATE_USER_ID as CREATE_U4_5_0_, s_5_.UPDATE_USER_ID as UPDATE_U5_5_0_, s_5_.CREATE_DT as CREATE_DT5_0_, s_5_.UPDATE_DT as UPDATE_DT5_0_, s_6_.PAGE_NUMBER as PAGE_NUM2_6_0_, s_6_.CUSTOMER_ID as CUSTOMER3_6_0_, s_6_.CREATE_USER_ID as CREATE_U4_6_0_, s_6_.UPDATE_USER_ID as UPDATE_U5_6_0_, s_6_.CREATE_DT as CREATE_DT6_0_, s_6_.UPDATE_DT as UPDATE_DT6_0_ from Survey_Indice s where ROWNUM < 4
17:43:48,883 [main] WARN JDBCExceptionReporter:38 - SQL Error: 904, SQLState: 42000
17:43:48,883 [main] ERROR JDBCExceptionReporter:46 - ORA-00904: "S_6_"."UPDATE_DT": invalid identifier

17:43:48,883 [main] WARN JDBCExceptionReporter:38 - SQL Error: 904, SQLState: 42000
17:43:48,883 [main] ERROR JDBCExceptionReporter:46 - ORA-00904: "S_6_"."UPDATE_DT": invalid identifier

17:43:48,893 [main] ERROR JDBCExceptionReporter:38 - SQLException occurred
java.sql.SQLException: ORA-00904: "S_6_"."UPDATE_DT": invalid identifier

---------------------------------------------------------------------------------
----------------------------------------------------------------------

WHY NEED "AS" after FROM TABLE "AS" table_alias?

This below is just a simple class with no children.
the hibernate generated query doesn't run on toad with exactly the same error msg due to "as" being there. Please correct the documentation if this "as" doesn't belong there.


if i run it with this strange sql (why do you need "as" after from table )

select s.* from Survey as s where rownum<4

testGetSurvey is called
Hibernate: select s.* from Survey as s where rownum<4
17:03:19,191 [main] WARN JDBCExceptionReporter:38 - SQL Error: 933, SQLState: 42000
17:03:19,201 [main] ERROR JDBCExceptionReporter:46 - ORA-00933: SQL command not properly ended

17:03:19,201 [main] WARN JDBCExceptionReporter:38 - SQL Error: 933, SQLState: 42000
17:03:19,201 [main] ERROR JDBCExceptionReporter:46 - ORA-00933: SQL command not properly ended

17:03:19,211 [main] ERROR JDBCExceptionReporter:38 - SQLException occurred
java.sql.SQLException: ORA-00933: SQL command not properly ended

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:81)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:629)
at net.sf.hibernate.loader.Loader.doResultSet(Loader.java:171)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:113)
at net.sf.hibernate.loader.Loader.find(Loader.java:736)
at net.sf.hibernate.loader.


Top
 Profile  
 
 Post subject: sorry about the rudeness
PostPosted: Thu Oct 23, 2003 12:11 am 
Newbie

Joined: Wed Oct 22, 2003 3:05 am
Posts: 9
I didn't mean to be rude, my apologies to Max and the hibernate team.

Of course, the query is complicated, because the mapping has bunch of joins. (how do you turn off left outer joins though?)

however, the sql string that is coming out isn't working.

i am reverting back to HQL. :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
createSQLQuery() does not support joined-subclass mappings. This seems reasonably difficult to implement, but maybe Max has some ideas.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If it is a joined-subclass then you need to do the joins yourself when using createSQLQuery()!

You need to provide all the attributes needed for the entity (and all it's super-classes) before Hibernate can process the generated resultset - and to get the resultset working you need to provide an sql statement that returns all the attribute needed for the object/class you are trying to query on....

_________________
Max
Don't forget to rate


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

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.