users@glassfish.java.net

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

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Mon, 25 Jan 2010 17:02:45 -0800

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.

-Mitesh
>
> Farrukh Najmi wrote:
>>
>> Thanks Mitesh for the info. I have worked around this issue by
>> generating Serializable bindings but now am seeing other issues in
>> EclipseLink.
>> I am realizing that I should not be in EclipseLink code at all since
>> I use hibernate JPA provider. Please confirm.
>>
>> If true then there is something that has changed between GF V3
>> Prelude and GF V3 Final that impact which EntityManagerFactory my
>> code creates. Seems that right now it is creating the one for
>> EclipseLink rather than for hibernate and that is where all my
>> problems seem to be originating from. It is also possible that my
>> code needs to be made more deterministic in which EnityManagerFactory
>> is being created.
>>
>> I will debug this some more but do let me know if you spot an obvious
>> reason why I am getting into EclipseLink code when using hibernate
>> JPA and how I can avoid it. Thanks.
>>
>
>