4

How can I change the name or path of the hibernate configuration file hibernate.cfg.xml in a tapestry application?

4

1 に答える 1

5

In the class AppModule there are two methods that need to be changed or created:

  1. contributeApplicationDefaults, to disable the default configuration
  2. 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

于 2012-10-30T14:23:56.080 に答える