How to use a custom hibernate.cfg.xml file path in Tapestry5
hibernate, tapestry
Solution
In the class `AppModule` there are two methods that need to be changed or created:
- `contributeApplicationDefaults`, to disable the default configuration
- `contributeHibernateSessionSource` to provide your own.
public static void contributeApplicationDefaults(
MappedConfiguration<String, Object> configuration) {
// Disable call to hibernate.configure() to call it manually
configuration.add(HibernateSymbols.DEFAULT_CONFIGURATION, "false");
}
public void contributeHibernateSessionSource(
OrderedConfiguration<HibernateConfigurer> configurer) {
configurer.add("hibernate-session-source", new HibernateConfigurer() {
public void configure(org.hibernate.cfg.Configuration configuration) {
configuration.configure("my-hibernate.cfg.xml");
}
});
}
The id `hibernate-session-source` is arbitrary, anything seems to work. In this discussion it's suggested to choose a unique one. Tested in Tapestry 5.3.6
Problem
How can I change the name or path of the hibernate configuration file `hibernate.cfg.xml` in a tapestry application?