Home > Hibernate, Java, JBoss, WebLogic > java.lang.UnsupportedOperationException: The user must supply a JDBC connection

java.lang.UnsupportedOperationException: The user must supply a JDBC connection

If you get this with Hibernate it probably means that you have an error, or an incomplete persistence.xml file. I got this while migrating from JBoss to WebLogic server and had forgotten to migrate the configuration from JBoss’ *-ds.xml to persistence.xml.

It happens because of this bit of code (Hibernate’s ConnectionProviderFactory.java)

ConnectionProvider connections;
String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
if ( providerClass!=null ) {
	try {
		log.info("Initializing connection provider: " + providerClass);
		connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
	catch ( Exception e ) {
		log.error( "Could not instantiate connection provider", e );
		throw new HibernateException("Could not instantiate connection provider: " + providerClass);
else if ( properties.getProperty(Environment.DATASOURCE)!=null ) {
	connections = new DatasourceConnectionProvider();
else if ( properties.getProperty(Environment.URL)!=null ) {
	connections = new DriverManagerConnectionProvider();
else {
	connections = new UserSuppliedConnectionProvider();

It tries to load several connection providers based on the Environment properties, it can’t find any connection providers (since their corresponding properties are not defined in the persistence.xml) and it just returns the default UserSuppliedConnectionProvider which, alas, it’s getConnection method is the following

public Connection getConnection() {
	throw new UnsupportedOperationException("The user must supply a JDBC connection");

After fixing the error, my persistence.xml is the following

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
   <persistence-unit name="myUnit" transaction-type="JTA">


		<property name="hibernate.connection.provider_class" value="org.hibernate.connection.DatasourceConnectionProvider"/>
	   	<property name="hibernate.connection.datasource" value="myDatasource"/>
	   	<property name="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
	   	<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
	   	<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
        <property name="hibernate.hbm2ddl.auto" value="validate"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.default_schema" value="MYSCHEMA"/>
	 <property name="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/>

  1. java fan
    9 June 2011 at 1:28 pm

    Thanks for the info but I m still missing some info. Would you please upload your spring config, so that I know which datasource you are using. Is it server provided or you have defined “myDatsource” in spring context.

  2. 11 June 2011 at 9:16 am

    I was not using spring, so I don’t have a spring configuration file. Can you post your persistence.xml to have a look?

  3. 28 July 2011 at 4:53 pm

    I am having same problem, here is my xml


  4. 29 July 2011 at 10:58 am

    Can’t see your persistence.xml. Can you post it again?

  1. 9 December 2014 at 6:51 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: