-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: "No suitable driver" problem with Hibernate3, Post
PostPosted: Fri Nov 07, 2008 3:46 pm 
Newbie

Joined: Fri Nov 07, 2008 3:43 pm
Posts: 2
Hi.

Does anybody know what's going on here:

I run hibernate 3.2.6 against a PostgreSQL 8.3 (installed via fink) database on my Mac OS X. The setup works fine when I use Java 6 and the JDBC 4 driver (postgresql-8.3-603.jdbc4). However, I need this stuff to work with Java 5 and (hence) JDBC 3 (postgresql-8.3-603.jdbc3). When I change the jar in the classpath and switch to Java 5 (I do this in eclipse), I get the following error when trying to create a session from SessionFactory:

Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
<Rows clipped for readability>
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)

What's the problem here? I cannot see it. Here is my hibernate configuration:

<hibernate-configuration>

<session-factory>
<property name="connection.url">jdbc:postgresql:test</property>
<property name="connection.username">postgres</property>
<property name="connection.password">p</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping resource="com/mydomain/MyClass.hbm.xml"/>
</session-factory>
</hibernate-configuration>

The driver jar is definitely in the classpath, and I also do not manage to get any errors with this direct JDBC test code:

public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://localhost/test","postgres", "p");
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2008 6:53 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Don't you also need:

Code:
<property name="connection.driver_class">org.postgresql.Driver</property>


in your configuration file? Though I don't know why it would work without this in Java 6.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2008 8:03 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Java 6 has a JDBC enhancement that auto-loads the driver class:

http://www.onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Sun Nov 09, 2008 5:07 pm 
Newbie

Joined: Fri Nov 07, 2008 3:43 pm
Posts: 2
Thank you nordborg and thatmikewilliams! My problem was solved. Somehow I had copied an example where the driver-class property was not present. And because it worked with JDBC4/Java6-setup I couldn't figure out that there could have been a problem with the config file.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.