Here's the code that I am using:
Code:
private SessionHandler(Properties props) throws HibernateException {
// reads in hibernate.properties implictly for database connection settings
cfg = new Configuration();
// attempt to use hibernate.cfg.xml
try {
cfg.configure();
} catch (HibernateException he) {
logger.info("Can't find \"hibernate.cfg.xml\" in classpath.");
}
// add base classes
cfg
.addClass(Channel.class)
.addClass(Item.class)
.addClass(ItemGuid.class)
.addClass(ItemEnclosure.class)
.addClass(ItemSource.class)
.addClass(Cloud.class)
.addClass(Category.class)
.addClass(ChannelGroup.class)
.addClass(ChannelSubscription.class)
.addClass(Image.class)
.addClass(ItemMetadata.class)
.addClass(TextInput.class);
// If Properties were supplied then use them as the final override
if (props != null) cfg.addProperties(props);
// get session factory
sessions = cfg.buildSessionFactory();
}
When I call this with the following:
Code:
Properties hibernateProps = new Properties();
hibernateProps.setProperty("hibernate.connection.url", "jdbc:hsqldb:" + dbPath);
new SessionHandler(hibernateProps);
It acts as if other properties than the URL have been lost, because I get an error message saying "unknown username" referring to the JDBC 'user' property.