We have a custom UserType implementation which is used by our HBM files and is instantiated by Hibernate using reflection. The UserType needs to do some post-construction configuration and validation. In particular it needs a reference to the SessionFactory so that it can obtain the ClassLoaderService. Currently we are implementing ParameterizedType.setParameterValues() and using some clunky work-around code to obtain the SessionFactory out-of-band. It would be helpful if Hibernate could provide the SessionFactory to UserTypes early in their life-cycle. A few ideas about how that could be provided:
- UserTypes could optionally provide a constructor which accepts a SessionFactory
- UserTypes could optionally implement some interface with setSessionFactory() method (which would be invoked before setParameterValues()).
Hopefully this makes sense. Thanks to the Hibernate team for a great product. |