}
}
protected SessionFactory createSessionFactory() throws ClassNotFoundException
{
AnnotationConfiguration configuration = new AnnotationConfiguration();
// setup non-default naming strategy
if (namingStrategy != null)
{
configuration.setNamingStrategy(namingStrategy);
}
// Programmatic configuration
if (cfgProperties != null)
{
Properties props = new Properties();
props.putAll(cfgProperties);
configuration.setProperties(props);
}
Hashtable<String, String> jndiProperties = Naming.getInitialContextProperties();
if ( jndiProperties!=null )
{
// Prefix regular JNDI properties for Hibernate
for (Map.Entry<String, String> entry : jndiProperties.entrySet())
{
configuration.setProperty( Environment.JNDI_PREFIX + "." + entry.getKey(), entry.getValue() );
}
}
// hibernate.cfg.xml configuration
if (cfgProperties==null && cfgResourceName==null)
{
configuration.configure();
}
else if (cfgProperties==null && cfgResourceName!=null)
{
configuration.configure(cfgResourceName);
}
// Mapping metadata
if (mappingClasses!=null)
{
for (String className: mappingClasses)
{
configuration.addAnnotatedClass(ReflectHelper.classForName(className));
}
}
if (mappingFiles!=null)
{
for (String fileName: mappingFiles)
{
configuration.addFile(fileName);
}
}
if (mappingJars!=null)
{
for (String jarName: mappingJars)
{
configuration.addJar(new File(jarName));
}
}
if (mappingPackages!= null)
{
for (String packageName: mappingPackages)
{
configuration.addPackage(packageName);
}
}
if (mappingResources!= null)
{
for (String resourceName : mappingResources)
{
configuration.addResource(resourceName);
}
}
configuration.setInterceptor(new HibernateSecurityInterceptor(configuration.getInterceptor()));
return configuration.buildSessionFactory();
}