-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to retrieve Column Names of a Table through Hibernate
PostPosted: Fri Sep 02, 2005 6:47 am 
Newbie

Joined: Wed Aug 24, 2005 12:07 pm
Posts: 17
Hi Friends,
I want to retrieve column names of a table through hibernate.How can I do that?
What is the query for that?Please let me know if anyone has idea about it.
Thanks in Advance,
Chirag


Top
 Profile  
 
 Post subject: Re: How to retrieve Column Names of a Table through Hibernat
PostPosted: Fri Sep 02, 2005 9:51 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
chiku_78 wrote:
Hi Friends,
I want to retrieve column names of a table through hibernate.How can I do that?
What is the query for that?Please let me know if anyone has idea about it.
Thanks in Advance,
Chirag


Well, you could probably map objects to the system tables that hold the relevent information - but this is of course entirely dependent on the database you're using. What database are you using?

_________________
- Matt


Top
 Profile  
 
 Post subject: I am use MySQL database
PostPosted: Tue Sep 06, 2005 2:18 am 
Newbie

Joined: Wed Aug 24, 2005 12:07 pm
Posts: 17
Hi,
I m using MySQL as a backend.If you have any idea about retrieval of column names then please let me know.
Thanx and Regards,
Chirag.


Top
 Profile  
 
 Post subject: Re: How to retrieve Column Names of a Table through Hibernat
PostPosted: Tue Sep 06, 2005 3:15 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
chiku_78 wrote:
you could probably map objects to the system tables


... or he could call org.hibernate.cfg.Configuration.getClassMapping().getProperty().getColumnIterator() ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:21 am 
Newbie

Joined: Tue Sep 06, 2005 2:58 am
Posts: 7
Try this code:

public static String getColumnName(Class aClass, String aPropertyName) {
// configuration is your hibernate org.hibernate.cfg.Configuration
PersistentClass pClass = configuration.getClassMapping(aClass.getName());

Property pProperty = pClass.getProperty(aPropertyName);
Column column = null;
if (pProperty.getColumnSpan() > 1) {
// Component, more difficult
} else {
column = (Column) pProperty.getColumnIterator().next();
}
return column.getName();
}


Greetingz

STeve


Top
 Profile  
 
 Post subject: Re: How to retrieve Column Names of a Table through Hibernat
PostPosted: Tue Sep 06, 2005 9:38 pm 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
dennisbyrne wrote:
chiku_78 wrote:
you could probably map objects to the system tables


... or he could call org.hibernate.cfg.Configuration.getClassMapping().getProperty().getColumnIterator() ;-)


That assumes he has a property mapped to the column name. The original post made no such indication.

To the original poster:
Check out chapter 21 of the mysql manual entitled "The INFORMATION_SCHEMA Information Database" for the info you need. Take a close look specifically at the sections labeled "The INFORMATION_SCHEMA TABLES Table" and "The INFORMATION_SCHEMA COLUMNS Table." It would take a little thought of course, but you should be able to map some objects to those tables in a way which would allow you to perform HQL queries to get the info you need. You'll just need to be careful in your choice of primary keys.

_________________
- Matt


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