wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes The user must supply a JDBC connection - Hibernate Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "The user must supply a JDBC connection - Hibernate Error" Watch "The user must supply a JDBC connection - Hibernate Error" New topic

The user must supply a JDBC connection - Hibernate Error

Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75

I am new to hibernate. I am trying out some examples. Here is what I did.

a) Created a User.hbm.xml mapping which maps 5 column names out of 10 columns from t_user table.
b) Created User.java with those mapped columns (setter and getter)
c) Created a stand along class with main method to test.

Following is the code snippet which selects all users from t_user table.

Configuration cfg = new Configuration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect")
test.factory = cfg.buildSessionFactory();
List users = test.viewAllUsers();
viewAllUsers() method

List users = null;
Session s = factory.openSession();
System.out.println("Connection:"+s.isConnected()); //this is printing
Transaction tx=null;
try {
tx = s.beginTransaction();
System.out.println ("Transaction"+tx.isActive()); //this is not printing.
users = s.createQuery("from User").list();
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
finally {

Exception is :
Mar 5, 2008 4:08:08 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Yep, you have no JDBC connections for Hibernate to use, Hibernate comes with C3PO Connection Pool. I highly recommend either using Annotations or a hibernate.cfg.xml instead of building your SessionFactory from code, but that is my preference and for samples and tests you are ok doing it in code, I just tend to not do it that way.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Thanks, I am using XML now. I downloaded the MSSQL2005 sqljdbc.jar file and is in my class path along with other hibernate jars. I am using RAD6.0. The error is :

SEVERE: No suitable driver
org.hibernate.exception.JDBCConnectionException: Cannot open connection


<!-- a SessionFactory instance listed as /jndi/name -->

<!-- properties -->
<property name="connection.driver_class">
<property name="connection.url">
<property name="connection.username">usr1</property>
<property name="connection.password">pwd!</property>
<property name="dialect">
<property name="show_sql">false</property>

<!-- mapping files -->
<mapping resource="com/hibernate/test/User.hbm.xml" />


[ March 06, 2008: Message edited by: Vinod Kumar ]
Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75

Please ignore my request...I found my mistake, for SQL Server 2005, there is a differece in connection URL string.

<property name="connection.url">



[ March 06, 2008: Message edited by: Vinod Kumar ]
I agree. Here's the link: http://aspose.com/file-tools
subject: The user must supply a JDBC connection - Hibernate Error
Similar Threads
Collections - Hibernate
RE: accessing database using JNDI
java.sql.SQLException: No suitable driver
Weblogic 10.3- EJB3 - Hibernate "The user must supply a JDBC connection" Exception
Caching Issues with Hibnernate