Sunday 6 April 2014

Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection

I got this error when I tried to persist  a row in the student table. I was using SQL Server 2008 R2 and Hibernate.
Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
My hibernate.cfg.xml file is as follows:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
 
   <property name="url">jdbc:sqlserver://MYSERVER:1433;databaseName=MYDB</property>
<property name="username">sa</property>
<property name="password">MYPASSWORD</property>
<property name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>

<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.generate_statictics">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">create</property>


<mapping class="Student" />
</session-factory>
</hibernate-configuration>

The root cause of this error is  the incorrectly specified property names. Actually I copied the property names from the bean which was used to initialize the data source in spring from some other project. And out of my negligence forgot to check the property names.

Finally I landed with the correct configuration:
 <property name="hibernate.connection.url">jdbc:sqlserver://AXIOM:1433;databaseName=S3H4</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>


Note that its also OK if you give just connection.url and so on instead of hibernate.connection.url

No comments:

Post a Comment