aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem with Hibernate and Oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with Hibernate and Oracle" Watch "Problem with Hibernate and Oracle" New topic
Author

Problem with Hibernate and Oracle

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8912
    
    8

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

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

Joined: Oct 29, 2001
Posts: 8912
    
    8

Thanks, but I still get the same error:



Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

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

Joined: Oct 29, 2001
Posts: 8912
    
    8

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

Joined: Jan 22, 2007
Posts: 196
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

Joined: Oct 29, 2001
Posts: 8912
    
    8

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

Joined: Feb 07, 2012
Posts: 344

Would the following approach work?
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
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

Joined: Oct 29, 2001
Posts: 8912
    
    8

The code looks like this now:



I got the same error:

Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

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

Joined: Jan 22, 2007
Posts: 196
Please try following code.

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8912
    
    8

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

Joined: Jan 22, 2007
Posts: 196
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

Joined: Jan 22, 2007
Posts: 196
PS if you look at the log, the application is trying to use cclinic

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8912
    
    8

Piyush Mangal wrote:Please try following code.


Same error as before.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

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

Joined: Sep 12, 2008
Posts: 507
- 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

Joined: Mar 24, 2008
Posts: 3832

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?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ben Fisher
Greenhorn

Joined: Apr 03, 2012
Posts: 1
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

Joined: Apr 17, 2008
Posts: 4
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

Joined: Oct 28, 2005
Posts: 9
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Hibernate and Oracle