So you’re introducing a backchannel to write to the database, correct? Bad! Bad! Beware of the caches – The db might contain stale information compared to, for example, ActiveObjects.
If you request to inject the
PluginHibernateSessionFactory in the constructor arguments, do you get it? (don’t forget to add it as component-import in atlassian-plugin.xml). It works in Confluence and that’s the most canonical way.
Otherwise, use this algorithm which has never failed me yet:
- If null, load the driver’s class using
Class.forName(driverClass), then try again to call
- If null, load the class from
- If still null, instantiate the driver directly with
driverClass.newInstance(). This fails with some badly-programmed drivers which require to be singleton (and that’s why we try using the DriverManager first), but sometimes there’s no other way.
Also, once you get this reference, cache it, because you don’t want to call
newInstance() for each request. The resulting script, with all fallbacks, try/catch and conditions, should be around 50-70 lines long.