-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to get Column Names of Database Table using Hibernate
PostPosted: Wed Nov 22, 2006 12:59 am 
Newbie

Joined: Thu Nov 16, 2006 9:35 am
Posts: 3
Dear All,

As per my project, I need to display all the column names of a table on JSP.
i.e i need to display fields on JSP dynamically.depends upon user credentials, user should get registration page& the fields on the page should come from database.
My table is like :

Id | First Name | Last Name |
-----|---------------|-----------------
1 | ram | chen |
2 | som | sun |
--------------------------------------

Now i have to get these field names(Id,First Name,Last Name) & should display these fieldson JSP

I am using hibernate3, I am using MySql databse----
How to get column names from database?

[Please note ,i dont want values in that columns,but only column names]

If any one knows please provide me the solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 9:24 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
One way would be to get the property names and the manipulate

ClassMetadata classMetadata = sessionFactory.getClassMetadata(Test.class);
classMetadata.getIdentifierPropertyName(); --> for the id
classMetadata.getPropertyNames(); --> for the propertyNames[]

Hope this helps and if so please do rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 12:29 am 
Newbie

Joined: Thu Nov 16, 2006 9:35 am
Posts: 3
Thanks buddy. Although yours code has not provided complete solution to my problem,but it helped me a lot.!!.

Yours code will help to get variable names of a class.But in my case ,i need to get column Names of a databse table.

Please help me in this !!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 6:04 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
look into
org.hibernate.mapping.PersistentClass

and

org.hibernate.cfg.Mappings

that should solve your problem.

please do rate


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