• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Hibernate and Oracle

 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used Hibernate before with Derby, but I can't seem to get it working with Oracle. I'm using Oracle 9.2.0.1 and Hibernate 4.1.1 and my code is as simple as it can get:



I get the following when I run this code:



I've updated my JDBC drivers, searched for hours and I'm at a loss. Anybody see anything wrong with my code?
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed you're using "default_schema" instead of "hibernate.default_schema", not sure if that would cause this issue. I think you also may need to specify a pool size for JDBC connections (hibernate.connection.pool_size).
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but I still get the same error:



 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never used Hibernate like this before; I normally use Hibernate's XML or properties config file. Did you try that approach too? Also, are all relevant jar files included on the java command line; i.e. Oracle driver (i.e. ojdbc14.jar) and Hibernate jars, etc.?
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using a hibernate.hbm.xml file with the same settings. I changed it to the programmatic configuration to post here, thinking one fewer file would make the code easier to read. The results were the same.
My classpath contains all the files in the Hibernate required directory as well as the current directory and the Oracle driver:
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Changing setProperty("hibernate.default_schema", "ZZZZZ") to setProperty("hibernate.default_schema", "zzzzz") to lower case.

https://forum.hibernate.org/viewtopic.php?f=6&t=998260


 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Piyush. I saw that post and tried it both ways. Same error. For the record, Oracle Enterprise Manager Console shows the schema name as all-caps (and I removed the "real" values from the code I posted and the code you quoted).
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would the following approach work?
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:Thanks, Piyush. I saw that post and tried it both ways. Same error. For the record, Oracle Enterprise Manager Console shows the schema name as all-caps (and I removed the "real" values from the code I posted and the code you quoted).


Try removing default schema property altogether and see if you are able to get rid of this error. Regarding connection URL jdbcracle:thin:@localhost:1521:WWWWW.
Are you sure WWWWW is valid SID?

 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code looks like this now:



I got the same error:

 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:
Joe Ess wrote:Thanks, Piyush. I saw that post and tried it both ways. Same error. For the record, Oracle Enterprise Manager Console shows the schema name as all-caps (and I removed the "real" values from the code I posted and the code you quoted).


Try removing default schema property altogether and see if you are able to get rid of this error. Regarding connection URL jdbcracle:thin:@localhost:1521:WWWWW.
Are you sure WWWWW is valid SID?


Did you try the following syntax:
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try following code.

 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:
Try removing default schema property altogether and see if you are able to get rid of this error. Regarding connection URL jdbcracle:thin:@localhost:1521:WWWWW.
Are you sure WWWWW is valid SID?


I removed the schema property. Same error. "WWWWW" appears in the tnsnames.ora and that whole connection URL is a copy/paste from a functioning Plain Old JDBC application. I just gave it a try and it works fine:


 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:
Piyush Mangal wrote:

I removed the schema property. Same error. "WWWWW" appears in the tnsnames.ora and that whole connection URL is a copy/paste from a functioning Plain Old JDBC application. I just gave it a try and it works fine:




Can you post the content of DBConnector ?
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS if you look at the log, the application is trying to use cclinic

 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:Please try following code.


Same error as before.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can always download the Hibernate source code and see if you can find anything there: http://sourceforge.net/projects/hibernate/files/hibernate4/

The null pointer issue seems to originate from org.hibernate.engine.jdbc.internal.JdbcServicesImpl on the last line shown below:


So I suspect that "dialect" is a null object; not sure why. I thought it could have been related to something in ServiceRegistryImplementor, which is something new in Hibernate 4: https://community.jboss.org/wiki/HibernateCoreMigrationGuide40
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Try downloading the hibernate jar again, may be this one is corrupted?
- Try different combinations of dialect and hibernate versions to separate the issue.

Not sure if order of property matters, I have dialect,url,usename,passwprd and driver class. I do not have default schema. and I have 10g dialect.

Good luck!
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:I tried using a hibernate.hbm.xml file with the same settings...

You meant the cfg.xml file right? I also suggest first try with a sample form your distribution with xml config and see. If you already done so, did it work?
 
Ben Fisher
Greenhorn
Posts: 1
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To close the loop on this, I had to add the following property to hibernate.cfg.xml to get it to work for me:

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
 
Steven Lawrence Hunter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Fisher wrote:To close the loop on this, I had to add the following property to hibernate.cfg.xml to get it to work for me:

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>


Thank you! I had the same problem, which the above resolved.
 
Bob Carpenter
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Fisher wrote:To close the loop on this, I had to add the following property to hibernate.cfg.xml to get it to work for me:

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>


Thanks Ben! This solved my problem too.

I was working fine on Win7/Oracle 10g DB, but when I moved my build over to SunOS using same 10g DB I was getting the error. Googling the first two lines of the exception brought me here.

Adding the new property didn't hurt my Win7 build either.

--Bob
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic