-->
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.  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Tue Apr 24, 2012 8:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The difference appears to lie in java.lang.ClassLoader#loadClass versus java.lang.Class#forName. Looking through java.lang.ClassLoader source, java.lang.ClassLoader#loadClass (which is the method currently used in Hibernate's ClassLoaderService) does not "resolve" a class and apparently part of that resolve process is calling static initializers (such as those needed by JDBC Drivers not providing a service locator file to register themselves).

In my preliminary testing, switching from:
Code:
ClassLoader cl = ...;
cl.loadClass( driverClassName );


to:
Code:
ClassLoader cl = ...;
Class.forName( driverClassName, true, cl );


should resolve the issue. The 'true' value passed in (as parameter called initialize) seems to be the same function as the inaccessible "resolve" functionality of ClassLoader.

So really bolsover, your Driver never was regsitering itself...


Top
 Profile  
 
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Tue Apr 24, 2012 10:01 am 
Regular
Regular

Joined: Sat Apr 23, 2005 7:28 am
Posts: 52
previously, in debug in class ClassLoaderServiceImpl, I saw a call to:
Code:
return (Class<T>) classClassLoader.loadClass( className );
and no exception thrown.

I had acutaully tried changing this to:
Code:
Class<T> clazz = classClassLoader.loadClass( className );
return clazz;


so I could focus on the return clazz - and found the expected com.pervasive.jdbc.v2.Driver was being returned and making me believe that it had been registered.

I'm not quite sure where you are making the change to
Code:
ClassLoader cl = ...;
Class.forName( driverClassName, true, cl );
??

Not in ClassLoaderServiceImpl I guess since that porcesses many other services besides JDBC?


Top
 Profile  
 
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Tue Apr 24, 2012 11:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Loading a class is a 2 step process:
  • Loading its bytecode and making a Class reference
  • This process of resolving.

ClassLoader#loadClass only involves step (1). Class#forName involves both.

I actually am thinking about making this change in ClassLoaderServiceImpl. I am trying to think of a time when we would not want the returned Class to not be resolved, but I cannot think of any tbh.


Top
 Profile  
 
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Tue Apr 24, 2012 1:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I made that change to ClassLoaderServiceImpl under https://hibernate.onjira.com/browse/HHH-7272. Pull master and give it a try please.


Top
 Profile  
 
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Tue Apr 24, 2012 3:37 pm 
Regular
Regular

Joined: Sat Apr 23, 2005 7:28 am
Posts: 52
Sorry for tardy response - been driving back to home base from meeting with client.

As I'm not too familiar with the maven repository I just got copy of modified ClassLoaderServiceImpl rather than full hibernate-core. I built the new file and replaced 4.1.2 ClassLoaderServiceImpl class files with the new data.

I tested against PervasiveSql JDBC 2.0 Driver both with and without c3p0 - success is both cases

I also tested against MySql with both 'old' JDBC 2.0 driver (previously failed) and new JDBC 4.0 driver (previously OK)- success in all cases both with and without c3p0.

Excellent work - and my thanks for your perseverence with this - I'll be keeping a close look out for the 4.1.3 release and be sure to test when available.

Just as an aside, I did contact the guys at Pervasive - suggested they might want to get their Driver compliany with JDBC 4.0 - no reply yet.

db


Top
 Profile  
 
 Post subject: Re: Migration problem 4.1.0 to 4.1.2
PostPosted: Mon Apr 30, 2012 12:41 am 
Newbie

Joined: Mon Apr 30, 2012 12:33 am
Posts: 1
... just wanted to drop in and say that I am experiencing this same issue when trying to connect to an Oracle db.
[*] Like others have mentioned, calling Class.forName() before any Hibernate code is a successful work-around
[*] I'm using the up to date ojdbc6.jar driver.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 36 posts ]  Go to page Previous  1, 2, 3

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.