aspose file tools*
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
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
Author

The user must supply a JDBC connection - Hibernate Error

Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Friends,

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()
.addResource("com/hibernate/test/User.hbm.xml")
.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect")
setProperty("connection.driver_class","com.microsoft.jdbc.sqlserver.SQLServerDriver")
.setProperty("connection.url","jdbc:microsoft:sqlserver://sqlser:1930/dbname")
.setProperty("connection.username","user1")
.setProperty("connection.password","pwd1");
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();
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
s.close();
}

Exception is :
Mar 5, 2008 4:08:08 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Connection:true
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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


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



<hibernate-configuration>

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

<!-- properties -->
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://server:1930/dbname
</property>
<property name="connection.username">usr1</property>
<property name="connection.password">pwd!</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">false</property>

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

</session-factory>

</hibernate-configuration>
[ March 06, 2008: Message edited by: Vinod Kumar ]
Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Hi,

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

<property name="connection.url">

jdbc:sqlserver://server1:1930

</property>

Thanks,
Vinod
[ March 06, 2008: Message edited by: Vinod Kumar ]
 
Consider Paul's rocket mass heater.
 
subject: The user must supply a JDBC connection - Hibernate Error