-->
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.  [ 12 posts ] 
Author Message
 Post subject: Problem Urgent about sql
PostPosted: Thu Mar 11, 2004 10:15 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
Can I create sql instructions without mapping table in Hibernate.
Example:

I have a table call "TB_PESSOA" and some atributes like "CD_PESSOA", "NM_PESSOA", "DT_NASCIMENTO".

And I wanna do this sql:

SELECT * FROM TB_PESSOA

or specified some static or dinamic condicions

SELECT * FROM TB_PESSOA WHERE CD_PESSOA = {} AND NM_PESSOA = 'GOMES'

WHO CAN I DO THIS?
THANKS.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the question is, what do you want to do with the result? send it to your presentation layer?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 10:53 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
I wanna get some atributes without mapping table in Hibernate.
Because this table is a view on Oracle and I don


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 11:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
just do List result = session.find (SELECT A,B FROM TB_PESSOA )
this will return a list of Object[]
for example if A is a Varchar and B a Number

so Objet[] myResult = (Objet[] )result.get(0) (= 1st row)
myResult[0] --> is A ...
so you can do
myA = (String)myResult[0]
myB = (Integer)myResult[1]


This will work


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:04 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
Thank you guy, but if I do this happend this:

net.sf.hibernate.QueryException: undefined alias: TB_PESSOA [ SELECT TB_PESSOA.CD_PESSOA FROM TB_PESSOA ]

Remeber TB_PESSOA can


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
do you have some sql generated?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:17 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
This is error:

net.sf.hibernate.QueryException: undefined alias: TB_PESSOA [ SELECT TB_PESSOA.CD_PESSOA FROM TB_PESSOA ]

This is my source:

List lista = session.find(" SELECT p.CD_PESSOA FROM TB_PESSOA p");


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:26 pm 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
If the Table TB_PESSOA is not mapped to any object what is the point to use Hibernate instead of plain JDBC.
Anyway, from the doc, Hibernate needs the alias to the mapped class, even with the SQLQuery methods.

http://www.hibernate.org/hib_docs/reference/html/query-sql.html#query-sql-s1
Quote:
The three parameters provided to createSQLQuery() are:

*

the SQL query string
*

a table alias name
*

the persistent class returned by the query

The alias name is used inside the sql string to refer to the properties of the mapped class (in this case Cat). You may retrieve multiple objects per row by supplying a String array of alias names and a Class array of corresponding classes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:59 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
My full source using hibernate mapping except this table, can


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:07 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
Please help me anyone!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:30 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can't use Hibernate without mapping a table with Hibernate. You may use direct SQL/JDBC by calling session.connection().

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:31 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Statement s = session.connection().createStatement(" SELECT p.CD_PESSOA FROM TB_PESSOA p");


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