-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to get column names from hibernate query?
PostPosted: Tue May 08, 2007 8:38 am 
Newbie

Joined: Tue May 08, 2007 8:25 am
Posts: 1
Hibernate version: 3.1.3

Name and version of the database you are using: Oracle 10

Hi All,

In my project we are using Native-SQL for querying data from Oracle database.

Like
List products = this.getSession()
.createSQLQuery("Select * from Products").list();

Here, before or after executing query I want to get column names.

How to do?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 8:59 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
wut?

... Hibernate doesn't work like that. Column names are mapped to fields to a domain/data/pojo object. Which you will have for each table...
Then you use HQL not SQL to query for actual objects as opposed to raw data from the DB.
Try reading up on some hibernate basics. From what you posted it doesn't sound like you are using Hibernate at all.

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 9:21 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
The requirement looks a bit strange to me.
However, since you are working on Oracle, you can use this query.

iterator = session.createSQLQuery("select column_name from user_tab_columns where table_name = 'PRODUCTS'").list().iterator();
while(iterator.hasNext())
System.out.println(iterator.next());


It prints out all columns of Products table.
--------------------------------------------------
Rate the reply if you find it helpful


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