• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
J Ellis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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!
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic