Being the impatient guy that I am, I came up with the following hack for both issues by adding a filter to log4j. Let me know if anyone has a better idea:
Code:
/** holds parsing exceptions */
private List parsingExceptions = new ArrayList();
/** custom log4j filter to remove JCS messages and watch for XML exceptions */
private Filter filter = new Filter() {
public int decide(LoggingEvent event) {
LocationInfo info = event.getLocationInformation();
String className = info.getClassName();
if (CompositeCacheConfigurator.class.getName().equals(className)
&& "Could not instantiate auxFactory named \"DC\".".equals(event.getMessage())
&& "359".equals(info.getLineNumber())) {
return Filter.DENY;
}
if (net.sf.hibernate.util.XMLHelper.ErrorLogger.class.getName().equals(className)) {
parsingExceptions.add(event.getThrowableInformation().getThrowable());
}
return Filter.ACCEPT;
}
};
/**
* Configure the session factory
* @throws Exception
*/
public void configure() throws Exception {
if (sessionFactory != null) return;
Logger logger = Logger.getRootLogger();
for (Enumeration e = logger.getAllAppenders(); e.hasMoreElements(); ) {
((Appender) e.nextElement()).addFilter(filter);
}
net.sf.hibernate.cfg.Configuration cfg = new net.sf.hibernate.cfg.Configuration();
List classNames = Configuration.getInstance().getMappedClasses();
for (Iterator i = classNames.iterator(); i.hasNext(); ) {
cfg.addClass(classForName((String) i.next()));
}
if (parsingExceptions.size() > 0) {
throw new Exception("Error occured parsing Hibernate XML files. See log for more details");
}
sessionFactory = cfg.buildSessionFactory();
}