Hi John,

You can use the SessionFilter[1] to create a thread local SessionContext[2] each request. The SessionContext is automatically configured via a hibernate.cfg.xml file on the classpath. I haven't used Hibernate in a while so not sure if you can configure a naming strategy in the hibernate.cfg.xml or through System properties. If not, you can implement your own SessionContext subclass for custom configuration. For example:

public class MySessionContext extends SessionContext {
  public Configuration createConfiguration() {
    Configuration config = new Configuration();
    config.setNamingStrategy(...);
    return config;
}

and setup the custom context in a filter:

public class MySessionFilter extends SessionFilter {

  public void init(FilterConfig filterConfig) throws ServletException {
    MySessionContext context = new MySessionContext();
    context.onInit(filterConfig.getServletContext());
  }
}

Its worth noting that HibernateForm uses SessionContext to lookup its Session and SessionFactory. So you don't need to use Click's SessionFilter/SessionContext to use HibernateForm, however you will need to override the HibernateForm methods getSession and getSessionFactory to lookup these objects when using an alternative session creation strategy.

Hope this helps.

kind regards

bob

[1]: 
http://click.apache.org/docs/extras-api/org/apache/click/extras/hibernate/SessionFilter.html
[2]: 
http://click.apache.org/docs/extras-api/org/apache/click/extras/hibernate/SessionContext.html

On 25/03/2010 12:23 AM, Kuhns, John wrote:
I'd like to use Hibernate forms, but can't seem to find any good
examples o= nline. In particular, I'd like to use my own configuration,
and I can't see= m to find anything that works/makes sense. I need to
use a custom naming st= rategy. Can anyone give me a few pointers?

Thanks,

John Kuhns


Reply via email to