-->
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.  [ 8 posts ] 
Author Message
 Post subject: problem with native sql query
PostPosted: Tue Jun 28, 2005 3:49 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
String qryString = "select {cov}.covno, {cov}.covdesc, {polcov}.limitsno from Coveragelku {cov}, Policycoverage {polcov}";

Query qry = session.createSQLQuery(qryString).addEntity("cov", Coverage.class).addEntity("polcov", Policycoverage.class);

List list = qry.list();

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

Above code executes the query as --

DEBUG - closing statement
DEBUG - could not execute query [select cov.covno, cov.covdesc, polcov.limitsno from Coveragelku cov, Policycoverage polcov]
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: covno0_
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

Why is it converting to covno0_ ?

Please help...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 4:17 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Have you tried to execute "select {cov.covno} ..." ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 4:23 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
baliukas wrote:
Have you tried to execute "select {cov.covno} ..." ?


Yes. That didn't work either.

String qryString = "select {cov.covno}, {cov.covdesc}, {polcov.limitsno} from Coveragelku {cov}, Policycoverage {polcov}";
Query qry = session.createSQLQuery(qryString).addEntity("cov", Coverage.class).addEntity("polcov", Policycoverage.class);
List list = qry.list();

above code gives below error...

DEBUG - select covno0_, covdesc3_0_, limitsno2_1_ from Coveragelku cov, Policycoverage polcov
Hibernate: select covno0_, covdesc3_0_, limitsno2_1_ from Coveragelku cov, Policycoverage polcov
DEBUG - preparing statement
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - could not execute query [select covno0_, covdesc3_0_, limitsno2_1_ from Coveragelku cov, Policycoverage polcov]
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'covno0_'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 5:20 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
Folks, pleas help!!

If my understanding is correct, native SQL queries are the ones written in database specific SQL format... said that, hibernate shouldnt be modifying the SQL.....

I'm confused why the query is being modified with "covno0_, covdesc3_0_, limitsno2_1_" ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 5:50 pm 
Newbie

Joined: Wed Jun 01, 2005 7:51 pm
Posts: 13
If this is Hibernate 3, you may wish to read chapter 16 of the doc for that
version.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 5:57 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
tuolumne wrote:
If this is Hibernate 3, you may wish to read chapter 16 of the doc for that
version.


I'm sorry... i dont understand what criteria queries have to do with what I'm looking for.... may be, you could elaborate a little, please....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 5:58 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
tuolumne wrote:
If this is Hibernate 3, you may wish to read chapter 16 of the doc for that
version.


I'm sorry... i dont understand what criteria queries have to do with what I'm looking for.... may be, you could elaborate a little, please....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 7:19 pm 
Newbie

Joined: Wed Jun 01, 2005 7:51 pm
Posts: 13
Chapter 17 (Native SQL) [which is Chapter 16 in my 3.0 doc] has
the following example:
Code:
String sql = "select cat.originalId as {cat.id}, " +
    "cat.mateid as {cat.mate}, cat.sex as {cat.sex}, " +
    "cat.weight*10 as {cat.weight}, cat.name as {cat.name} " +
    "from cat_log cat where {cat.mate} = :catId"

List loggedCats = sess.createSQLQuery(sql)
    .addEntity("cat", Cat.class)
    .setLong("catId", catId)
    .list();

Notice that this query is different than the one you included in
your postings. If you make yours look like the one above,
it'll probably work -- it has for me.


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