-->
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: could not execute query
PostPosted: Wed Feb 22, 2006 8:02 pm 
Newbie

Joined: Mon Feb 06, 2006 4:00 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Hi,

I am getting "could not execute query exception" when I try to execute SQL query through hibernate.

I am using DB2 database and Hibernate3.0.
I found that Hibernate is attaching the user name before the table instead of the schema name. Thats why it is giving that error.

Can anyone tell why Hibernate is not using schema name for executing queries even though i specified in configuration file.

Thanks
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 12:42 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not without sufficient configuration files, mapping files, and sample java code to see where you're going wrong.

Don't forget to use code tags when posting each bit. Feel free to strip out uninteresting parts of the files.


Top
 Profile  
 
 Post subject: please see the below code and configuration files
PostPosted: Thu Feb 23, 2006 1:34 am 
Newbie

Joined: Mon Feb 06, 2006 4:00 pm
Posts: 5
Giving "could not execute query" exception. I am executing against DB2 Mainframe.

Hibernate 3.0 version.


Hibernate configuration file:
---------------------------------

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- properties -->
<!-- Change the dialect if needed -->
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name ="batch_size">0</property>
<property name ="use_scrollable_resultsets">false</property>
<property name="connection.tuf_pool_name">SCP</property>
<property name="hibernate.default_schema">Z1YS001$</property>
<property name="show_sql">true</property>


<mapping resource="test/Student.hbm.xml"/>

</session-factory>
</hibernate-configuration>



Mapping File:
----------------------
<hibernate-mapping>
<class
name="Student"
table="STUDENT"
lazy="false" >

<id
name="name_id"
type="java.lang.String"
column="NAME_ID">
</id>

<property
name="type"
type="java.lang.String"
column="TYPE"/>

</class>
</hibernate-mapping>



Java code
---------------------
Session session = getSession();
StringBuffer query = new StringBuffer("select NAME_ID,TYPE from STUDENT");
List list = session.createSQLQuery(query.toString()).list()



Thanks
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 5:05 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Again, not enough information. I have theories, though. SQLQuery requires that you specify the return types. Try this:
Code:
List list = session.createSQLQuery(query.toString())
                   .addScalar("NAME_ID", Hibernate.INT)
                   .addScalar("TYPE", Hibernate.INT)
                   .list();
Obviously, adjust the types to suit.
If a Student class has nothing but those two fields, and you want to have Hibernate create a Student object from each row, then you can change that to
Code:
List list = session.createSQLQuery(query.toString())
                   .addEntity(Student.class)
                   .list();


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.