-->
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.  [ 5 posts ] 
Author Message
 Post subject: sql in hibernate without mapping
PostPosted: Fri Jul 21, 2006 4:16 pm 
Newbie

Joined: Thu May 25, 2006 12:21 pm
Posts: 11
can we write sql query in hibernate without using mapping.

like:
select * from emp;

where emp is my table name.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 4:24 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Yes. The result will be an one or more Object[] -- not very friendly to use.

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 9:01 pm 
Newbie

Joined: Thu May 25, 2006 12:21 pm
Posts: 11
thanks CWitherow ,

Do you know how i can use it.

As i am not sure how to use it.

I tried it but it throws an error saying no mapping found.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 12:28 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Code:
List results =
    session
        .createSQLQuery("SELECT col1, col2 FROM table1")
        .addScalar("col1", Hibernate.STRING)
        .addScalar("col2", Hibernate.INTEGER)
        .list();

for (Iterator iter = results.iterator; iter.hasNext(); ) {
    Object[] objs = (Object[])iter.next();
    String col1Value = (String)objs[0];
    Integer col2Value = (Integer)objs[1];
    ...
}


Note that the query is SQL, not HQL. You still need a SessionFactory and a Session.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 9:29 am 
Newbie

Joined: Thu May 25, 2006 12:21 pm
Posts: 11
thanks Curtis.

It was a great help!


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