Saturday, February 6, 2010

Hibernate, Tomcat 6.0 and mysql

My normal configuration stack is Spring, Hibernate and Oracle on Weblogic. Switched today to the lightweight mysql and Tomcat - blame it on limited RAM.

Issue: The error thrown up in the logs is
java.lang.UnsupportedOperationException: Not supported by BasicDataSource
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:899)
...

The configuration files are listed below

server.xml located at %CATALINA_HOME%/conf


context.xml located at %CATALINA_HOME%/conf


hibernate.cfg.xml




com.mysql.jdbc.Driver
java:comp/env/jdbc/products
true
org.hibernate.dialect.MySQLDialect
root
xxxxxx



Reason: Hibernate.jar/DatasourceConnectionProvider/getConnection method invokes Tomcat 6/BasicDataSource passing the username and password.
But the BasicDataSource getConnection(String username, String password) method throws UnsupportedOperationException.

Solution: Remove the credentials from the hibernate.cfg.xml file, retain 'em only in the datasource setting. This will result in the no argument getConnection method being invoked which is implemented in BasicDataSource

No comments: