-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate with NativeSQL
PostPosted: Tue Nov 08, 2005 8:22 am 
Newbie

Joined: Tue Nov 08, 2005 7:54 am
Posts: 1
Currently using hibernate 3.0 with JBoss.

I am trying to execute the following query to retrieve the first letter of values in the brand column of an oracle table called itc_brand

itcBrandAlphaList = hs.createSQLQuery("select distinct substr(ib.brand,1,1) as brandLetter from itcbrand ib").list();

There does not need to be a mapping for this , as I only want to retrieve the first letter of the brand column. There error I get when running the application is

java.sql.SQLException: ORA-00942: table or view does not exist

Do I need to create a mapping. If so how do I specify the column name, as it is not a column in the table, but a derived column value.

The table does exist in an oracle database.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 3:25 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
You can not just pass in an SQL query to the createSQLQuery method. It has a particular syntax that it is looking for.

for example if you SQL is:

SELECT u.id as id FROM users u

the string passed to the createSQL query would look like:

String sqlquery = "select u.is as {uzer.id} from users u";

session.createSQLQuery(sqlquery, "uzer", User.class).list();

the syntax for createSQLQuery is createSQLQuery(String string, String alias, Class classYouAreAliasing)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.