• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting property / column names from mapping file

 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1. I need to get the hibernate column name corresponding to a database column name that I have in my application. Is there a way to query the mapping file for that class / table and retrieve hibernate property name for a given column name ?
2. Is there also a way to get all the columns for a particular class / table in my application at runtime ?

Please can anyone tell me which API in hibernate would let me do this ?

Harsha
 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the API by which we can get the properties and with that retrieve the name of the column it is associated with.
By getting the Mapping class from the configuration object and then getting the property fform that.
I dont think there is a way to get the name of the Hibernate property if the name of the column is know.
If anyone knows otherwise, please let me know.

Thanks.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, mapping files are just XML so you could just parse them and use XPath to get the field name for a particular property. Not really sure why you would want to do this though.
 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initally when we designed the system, when we hadnt thought of hibernate yet; a requirement said that we had to assign rules to the columns of a table. But now it would have to be the fields of the hibernate file instead. So I was wondering if I could get the column names from hibernate and still maintain the same requirement.

Thanks.
Harsha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic