aspose file tools
The moose likes Object Relational Mapping and the fly likes Any way to access the Hibernate mapping files from the persistence objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Any way to access the Hibernate mapping files from the persistence objects?" Watch "Any way to access the Hibernate mapping files from the persistence objects?" New topic
Author

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

J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 27
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

Joined: Mar 28, 2012
Posts: 860

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

Joined: Aug 23, 2009
Posts: 27
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

Joined: Aug 23, 2009
Posts: 27
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any way to access the Hibernate mapping files from the persistence objects?
 
Similar Threads
Mappings and POJO's in different folders
SQL Server identity not generated in the Mapping Files
How to map .hbm.xml file in persistence.xml
Hibernate + Configuration.addClass Exception
Hibernate(newbie) - generating relational database from Object model