Hello everybody !
I just started to play with Hibernate 3 and was very happy to see the new dynamic mapping feature (no need for POJO classes anymore, when you want to do something dynamic). I am currently investigating how to integrate Hibernate into a Java based dynamic language, which I am just creating.
Up to yesterday I was really planning to dynamically generate POJO bytecode out of my object definitions, generate the mapping XML and pass all this to a Hibernate Configuration object. Crazy!
But this new feature could make my life a lot easier.
So I spent some hours digging into the source to see, where those maps are instantiated and found class DynamicMapInstantiator. (together with POJOInstantiator etc.)
Now I should explain what I want to do:
My dynamic objects all implement the Map interface, but of course they can do additional fancy things. There is something like a factory, that creates dynamic objects by their type name:
Code:
class Factory
{
static java.util.Map create(String typeName);
}
Now Hibernate creates HashMap instances. Of course I could take this instance, lookup the property "type" and then create my fancy object myself. But this would not work for related objects. I would have to walk the whole object graph and replace the hashmaps with my favoured objects.
So I was considering to just patch class DynamicMapInstantiator to return my kind of object. Since it implements the map interface everything should be fine (although I am not sure about side effects here)
Otherwise it could be smarter to slightly modify the DynamicMapInstantiator to allow for a user defined map factory.
Now my questions:
- would such a change have a chance to be accepted?
- how dangerous is it? (I am certainly not a Hibernate guru)
- is the new dynamic feature usable for all kinds of mappings already?
- if not, what are the current restrictions (I saw some TODO's regarding components.)
Any feedback is highly appreciated.
Best regards