• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any way to access the Hibernate mapping files from the persistence objects?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am writing a method for my persistence objects that I want to iterate through the <column> elements contained in my hbm.xml mapping files. Is there a way to access that information from my persistence object? I have been messing around with the SessionFactory and Configuration objects, and I have found a way to iterate through all of the attributes in the Java class itself, but not a way to figure out what those attributes are mapped to in the database via the hbm.xml files.


Thanks!
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you really need to do this, you are much better off using annotations (more modern approach anyway)

With the reflection API you can then iterate through your properties, and/or methods extract and process the @Annotation.

If you can access the hbm.xml file from your application, then you would have to XML parse it via dom/sax or helper classes.

Pat.
 
J Ellis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,

Thank you for the response! I did not realize that annotations are the more modern way to do this; I am very new to Hibernate and for some reason I thought that the xml mapping files were newer. I have done some more searching and found some roundabout ways to do what I need using the Configuration object to get the class and table mappings, and then iterating through some of the properties. Your approach, however, sounds much easier and more direct; I will start messing around with the annotations today and let you know how it turns out.


Thanks again,

Justin
 
J Ellis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pat (William),

Thanks again for the information. I was able to write a custom result class for Struts that builds the XML I need using the reflection interface into the annotations. Unfortunately, the whole thing is prohibitively slow and memory-hungry when dealing with the sheer amount of information that I need. I am looking into paging the data, and trying to find other best practices when dealing with information of this magnitude. Please let me know if you have any suggestions.


Thanks!

Justin
 
reply
    Bookmark Topic Watch Topic
  • New Topic