-->
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: Named query returning Object
PostPosted: Tue May 24, 2005 9:05 pm 
Newbie

Joined: Tue May 24, 2005 8:08 pm
Posts: 1
Hello:
I'm using the Hibernate 3.0 XML Mapping feature, that seems great for me, because I'm presenting data using XSL filters.
Now, I have a little question:
I'm trying to execute a named query. If I use the query of the form:
"from User" I have the result as a List of Elements. Now, if I specify the query as: "select u.userID, u.userName, u.roleID from User u", the result seems to be a java.lang.Object, and the application throws a "class cast exception" when I cast the List content to "Element".

Here are my configuration and code.

Thanks in advance for the answers.


Hibernate version:
3.0.2 - 3.0.3 - 3.0.4 - All the same behavior.
Mapping documents:
<hibernate-mapping>

<class entity-name="User" table="User" node="Usuarios">
<id name="userID" column="userID" node="Usuario" type="string" unsaved-value="null"/>
<property name="userPWD" column="userPWD" node="Clave" type="string"/>
<property name="roleID" column="roleID" node="Rol" type="integer"/>
<property name="userName" column="userName" node="Nombre" type="string"/>
<property name="creationDate" column="creationDate" node="Fecha_de_creacion" type="timestamp"/>
</class>

<class entity-name="Role" table="Role" node="Roles">
<id name="roleID" column="roleID" node="Rol" type="integer" unsaved-value="null"/>
<property name="roleDescription" column="roledescription" node="Descripcion" type="string"/>
<property name="creationDate" column="creationDate" node="Fecha_de_creacion" type="timestamp"/>
<set name="permission" table="Permission" node="Permisos">
<key column="roleID"/>
<many-to-many column="treeOptionID" entity-name="TreeOption" embed-xml="true"/>
</set>
</class>
<class entity-name="TreeOption" table="TreeOption" node="Arbol">
<id name="treeOptionID" unsaved-value="null" column="treeOptionID" node="Opcion" type="integer"/>
<property name="treeOptionParentID" column="treeOptionParentID" node="Padre" type="integer"/>
<property name="treeOptionLevel" column="treeOptionLevel" node="Nivel" type="integer"/>
<property name="treeOptionSequence" column="treeOptionSequence" node="Secuencia" type="integer"/>
<property name="treeOptionModule" column="treeOptionModule" node="Modulo" type="string"/>
<property name="treeOptionName" column="treeOptionName" node="Destino" type="string"/>
<property name="treeOptionDescription" column="treeOptionDescription" node="Descripcion" type="string"/>
<property name="creationDate" column="creationDate" node="Fecha_de_creacion" type="timestamp"/>
</class>

<!--select u.userID, u.userName, u.roleID from User u-->
<query name="userquery" cacheable="true" fetch-size="10"><![CDATA[
select u.userID, u.userName, u.roleID from User u
]]></query>

<query name="usersinrole" cacheable="true" fetch-size="10"><![CDATA[
from User u where u.roleID = ?
]]></query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession().getSession(EntityMode.DOM4J);
Transaction tx = session.beginTransaction();

l_oQuery = session.getNamedQuery(p_sQuery);

it = l_oQuery.list().iterator();

while (it.hasNext()) {
l_oElement = (Element)it.next();
l_sXMLData += l_oElement.asXML();
}
Full stack trace of any exception that occurs:
18:33:36,815 DEBUG myapp:69 - Element error: [Ljava.lang.Object;
java.lang.ClassCastException: [Ljava.lang.Object;
at com.mycompany.myapp.webservices.DatabaseQuery.getQueryResults(DatabaseQuery.java:58)
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:585)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:384)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:281)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:319)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:767)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
18
Name and version of the database you are using:
MySQL
The generated SQL (show_sql=true):
select user0_.userID as col_0_0_, user0_.userName as col_1_0_, user0_.roleID as col_2_0_ from User user0_
Debug level Hibernate log excerpt:
18:33:36,733 DEBUG QueryTranslatorImpl:240 - SQL: select user0_.userID as col_0_0_, user0_.userName as col_1_0_, user0_.roleID as col_2_0_ from User user0_
18:33:36,735 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
18:33:36,737 DEBUG SQL:324 - select user0_.userID as col_0_0_, user0_.userName as col_1_0_, user0_.roleID as col_2_0_ from User user0_
Hibernate: select user0_.userID as col_0_0_, user0_.userName as col_1_0_, user0_.roleID as col_2_0_ from User user0_
18:33:36,772 DEBUG AbstractBatcher:378 - preparing statement
18:33:36,778 DEBUG AbstractBatcher:306 - about to open ResultSet (open ResultSets: 0, globally: 0)
18:33:36,780 DEBUG Loader:398 - processing result set
18:33:36,781 DEBUG Loader:403 - result set row: 0
18:33:36,783 DEBUG Loader:821 - result row:
18:33:36,787 DEBUG StringType:86 - returning 'myID' as column: col_0_0_
18:33:36,789 DEBUG StringType:86 - returning 'This is my name' as column: col_1_0_
18:33:36,791 DEBUG IntegerType:86 - returning '1' as column: col_2_0_
18:33:36,794 DEBUG Loader:422 - done processing result set (1 rows)
18:33:36,796 DEBUG AbstractBatcher:313 - about to close ResultSet (open ResultSets: 1, globally: 1)
18:33:36,798 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
18:33:36,799 DEBUG AbstractBatcher:416 - closing statement
18:33:36,803 DEBUG PersistenceContext:789 - initializing non-lazy collections
1


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.