I'm trying to use Hibernate with Tomcat. I've got a few persistent classes located in WEB-INF/classes.
I'm using the singleton/ThreadLocal pattern. I initialize hibernate with this code in a static init method:
Code:
Properties props = new java.util.Properties();
props.load( SitecasterState.getContext().getResourceAsStream( "WEB-INF/hibernate.conf" ) );
Configuration config = new Configuration();
config.setProperties( props );
config.addDirectory( new File( SitecasterState.getContext().getRealPath( "WEB-INF/classes" ) ) );
factory = config.buildSessionFactory();
No Exceptions are thrown, I can use the config to do a succesfull SchemaExport in the same singleton.
hibernate.conf contains:
Code:
connection.datasource=jdbc/testdb
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
show_sql=false
use_outer_join=true
The problem arises when I try to use a Session. Hibernate can't find my persistent classes. It throws a MappingException, width the message: No persister for: [classname].
I've read the documentation on this issue and added <Loader delegate="false"/> to the configuration of the context. If I do a Class.forName() the persistent classes are loaded without trouble.
To me this doesn't really seem like a hibernate problem, but more like a Tomcat classloading problem.
Could anybody give me any clue on how to resolve this problem? I don't see what I'm doing different compared to the tomcat examples I've seen.