Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting property / column names from mapping file

 
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
 
    Bookmark Topic Watch Topic
  • New Topic