-->
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.  [ 10 posts ] 
Author Message
 Post subject: full select statement
PostPosted: Mon May 17, 2004 12:16 pm 
Newbie

Joined: Fri May 14, 2004 12:18 pm
Posts: 10
How do i use full select statement in the hibernate with spring-web application?

EX: select id, lastname||','||firstname from emp

I always got error if i put this string in the find(s) function.

-Henry


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not valid HQL. Either use createSQLQuery() or learn about HQL by reading the chapter in the documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Full select query...
PostPosted: Mon May 17, 2004 12:29 pm 
Newbie

Joined: Fri May 14, 2004 12:18 pm
Posts: 10
how do we call createSQLQuery in the following class:

public class EmpDaoSql extends HibernateDaoSupport
{
public List select Emp()
{
// ?? here ??
String s = "select id,lastname||','||firstname from emp";
createSQLQuery(s);
....
}
}

-Henry


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 12:30 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is all very well documented.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Error from full select query...
PostPosted: Mon May 17, 2004 12:50 pm 
Newbie

Joined: Fri May 14, 2004 12:18 pm
Posts: 10
I got the following error :

--------------------------------------------------------------------------------
12:46:55,365 ERROR - [util.JDBCExceptionReporter.logExceptions] Invalid column name
--------------------------------------------------------------------------------
my code is:
---------------------------------------------------------------------------------
String sqlString =
"SELECT dept.DEPTNO, dept.DNAME FROM Dept {dept}";

Session sess = getSession();

try {
Query qr = sess.createSQLQuery(sqlString, "dept", Dept.class);

resultList = qr.list();
...


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 12:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So you have an invalid column name.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 1:23 pm 
Newbie

Joined: Fri May 14, 2004 12:18 pm
Posts: 10
what is wrong with my column name?

13:21:10 SQL> desc dept
Name Null? Type
------------------------------- -------- ----
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)

String sqlString =
"SELECT dept.DEPTNO, dept.DNAME FROM Dept {dept}";

and domain class:

public class Dept implements java.io.Serializable {
private int DEPTNO;
private String DNAME;
private String LOC;
...
}

-Henry


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please read the docs and note that all examples and doc says that you can load entities with createsqlquery - not scalar values!

Thus: "...if you list each property explicitly, you must include all properties of the class and its subclasses!" <-- taken from the docs and unless you have an object with two properties DEPTNO and DNAME then you have not done as stated in the docs!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 4:05 pm 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
First of all what RDBMS are you using ? Some are case sensitive. Second why SQL if HQL can do ? And I agree Max if you mapping only contains native Types and no object relations then you SQL Statement is incorrect, because it will use dept as schema not as Object.

regards

Olaf


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 1:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
is has nothing to do with casesensivity but with the fact that he is only listing 2 column/properties from his object where he at least has shown the object has 3 and more properties. Thus when hibernate tries to build his object and wants to get LOC then it fails because it is not part of his output from the query.

_________________
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.  [ 10 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.