Hibernate version: 2.1.4
My boss has asked me to build a Generic Form class in Java (1.4.2) which takes parameters (Class, InstanceID, Datasource) and displays (generates) an HTML form for performing CRUD operations.
the parameters have the following meanings:
-----------------------------------------------------------------------------------
Class - the fully qualified name of the java class we will be persisting
InstanceId - if not null, represents the instance of the object we will be READING, UPDATING or DELETING. if null, we will be INSERTING.
Datasource - which datasource to use for persisting this object.
-----------------------------------------------------------------------------------
OK, that's the scenario. I had originally thought about using java reflection to build the list of properties the class has, and consequently build the text fields, radio buttons, checkboxes, etc according to naming conventions on the field level. But then I started getting into problems when I wanted to include too much information in the naming convention. FOR EXAMPLE: private String description_255_not-null
where description is the actual name of the property, 255 is the max length, and not-null indicates that its a required field. This is when I remembered that the *.HBM.XML document already contained this level of information on the properties and that it wouldn't be necessary to build this into a crazy-long naming convention.
(now for the question)
Is there a class within Hibernate that parses these *.HBM.XML and retrieves these properties? I have look around the API but to no avail... I tried this bit of code to see what it got me, but it only brought my the classes in the sessionFactory from Spring (which was useful, but not enough):
Code:
SessionFactory sessionFactory=(SessionFactory)ctx.getBean(sessionFactoryRef);
Map metaData=sessionFactory.getAllClassMetadata();
Also, I looked into these methods, but I could have gotten this information through java reflection:
Code:
EntityPersister.getPropertyNames();
EntityPersister.getPropertyTypes();
EntityPersister.getPropertyValues();
Again, I would need to be able to not only retrieve the fields themselves (i.e. description) but also the properties of the fields (i.e. length=255, not-null, etc) from the HBM.XML.
Thanks in advance for any help!
karokain
Code: