users@glassfish.java.net

Re: [hibernate EntityManager] No suitable driver found for jdbc:postgresql://localhost:5432/omar4

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Mon, 25 Jan 2010 21:14:04 -0500

Mitesh Meswani wrote:
> On 1/25/2010 4:13 PM, Farrukh Najmi wrote:
>> Hi Mitesh,
>>
>> After following instructions in:
>>
>> a)
>> http://blogs.sun.com/GlassFishPersistence/entry/using_hibernate_as_jpa_provider
>>
>> b) <gfv3-installdir>/hibernate/overview.txt
>>
>> I added "<provider>org.hibernate.ejb.HibernatePersistence</provider>"
>> to my persistence.xml file like and now I am getting the hibernate
>> EntityManagerFactory instead of the EclipseLink one (phew!).
> Great to know that your issue is resolved. The provider needs to be
> specified if you are using JavaSE style of persistence or using JavaEE
> style and not using the default provider which is EclipseLink for V3.
>>
>> But now I get a different error which also seems to be related to my
>> use of hibernate:
>>
>> WARNING: Could not obtain connection to query metadata
>> java.sql.SQLException: No suitable driver found for
>> jdbc:postgresql://localhost:5432/omar4
>> at java.sql.DriverManager.getConnection(DriverManager.java:602)
>> at java.sql.DriverManager.getConnection(DriverManager.java:154)
>> at
>> org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
>>
>> at
>> org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:114)
>>
>> at
>> org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2145)
>>
>> at
>> org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2141)
>> at
>> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1365)
>>
>> at
>> org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:858)
>>
>> at
>> org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:733)
>>
>> at
>> org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:152)
>>
>> at
>> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
>>
>>
>>
>> This seems to be a classloader type issue since the posgres driver is
>> definitely part of my war file. I have the following in my wars
>> WEB-INF/lib directory:
>>
>> postgres-jdbc-1.1.6.jar
>> postgres-8.3-603.jdbc3.jar
>>
>> So what could be causing this new problem?
> If you have followed instructions in the bolg, you have copied
> Hibernate in lib dir of appserver and hence a call to getConnection()
> from hibernate code results in use of class loader that does not have
> visibility into your war. You should either package both hibernate
> jars and database driver with the war or put both of them in lib dir
> of appserver.
>

Hi Mitesh,

This is to confirm that your suggested fix above worked like a charm.
Since my war had all my dependencies already packaged (thanks to maven)
I simply deleted the following jars in ~/glassfishv3/glassfish/lib:

rm antlr-2.7.6.jar commons-collections-3.1.jar dom4j-1.6.1.jar
hibernate3.jar javassist-3.9.0.GA.jar slf4j-*

Things are looking up and working now. Thanks for your kind help.

Lastly, this week is when Oracle / Sun deal is finalized. I wish you and
all my dear Sun colleagues the very best of luck in life after Sun.
I hope project Glassfish thrives at Oracle.

You guys are simply the best.

-- 
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com