In hibernate3.x ,hibernate provider a way to publish sessionFactory in jndi tree through jmx .
But it does not do best.
I think if it support auto san the hbm files in the jar or ear/war ,will be better and gracer.
Jboss hibernate jmx doest provider this feature.
why not learn from them?
the following code is how Jboss hibernate jmx service to scan hbm file:
Code:
/**
* Scan the current context's classloader to locate any potential sources of Hibernate mapping files.
*
* @throws DeploymentException
*/
private void scanForMappings() throws DeploymentException
{
// Won't this cause problems if start() is called from say the console?
// a way around is to locate our DeploymentInfo and grab its ucl attribute
// for use here.
URL[] urls = null;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl instanceof RepositoryClassLoader)
{
urls = ((RepositoryClassLoader)cl).getClasspath();
}
else if (cl instanceof URLClassLoader)
{
urls = ((URLClassLoader)cl).getURLs();
}
else
{
throw new DeploymentException("Unable to determine urls from classloader [" + cl + "]");
}
// Search the urls for each of the classpath entries for any containing
// hibernate mapping files or archives
for (int i = 0; i < urls.length; i++)
{
final File entry = new File(urls[i].getFile());
log.trace("checking classpath entry [" + entry + "]");
if (!entry.exists())
{
continue;
}
if (!entry.isDirectory())
{
// This entry is not a directory, meaning it is a file of
// some sort. If it is an archive, we are interested in it...
if (isArchive(entry))
{
log.trace("classpath entry was an archive file...");
archiveClasspathUrls.add(entry);
}
else
{
log.trace("classpath entry was a non-archive file...");
}
}
else
{
log.trace("classpath entry was a directory...");
// we have a directory, add it to the list of directory classpath urls
directoryClasspathUrls.add(entry);
}
}
}
but hibernate can not do the same as jboss hibenate jmx do.
Because there are difference between the classloaders in different server platform.
Maybe reading jar file or directory and filter the hbm.xml is more feasible.
what about your opinion?