-->
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: retrieving column names from a table
PostPosted: Tue Dec 21, 2004 3:41 am 
Newbie

Joined: Tue Dec 21, 2004 3:30 am
Posts: 2
hibernate 2.1.7

mysql 4.0.18

I'm having trouble searching through Google, the forums, and the API for a method to retrieve all the column names from a table in Hibernate. Would anyone know of a simple way to do this? I can build the native mysql sql query to do this for Hibernate, but I'm sure I'm missing the easier route.

Thanks for your help,
cjen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 5:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at the Configuration object - it allows you to gain access to all the class metadata on which you can find all the columns a class map to...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: here it is
PostPosted: Tue Dec 21, 2004 5:02 pm 
Newbie

Joined: Tue Dec 21, 2004 3:30 am
Posts: 2
Arg... Thanks max. It was right there in the FAQ and I overlooked it.

http://www.hibernate.org/118.html

Here's how you do get it if anyone is interested.

Code:
Configuration cfg = new Configuration().addClass(Table.class);
sessionFactory = cfg.buildSessionFactory();
PersistentClass pert = cfg.getClassMapping(Table.class);
Iterator iter = pert.getPropertyIterator();
          
while ( iter.hasNext() )
{
    Property prop = (Property) iter.next();
    System.out.println("Column Name: " + prop.getName());
}


cjen


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.