Recently had to upgrade one of my programs to go from some other database to Oracle. Luckily it uses hibernate, so i thought it would be hassle free. Well, i hit a few hiccups so here's how i finally got it to work. Note that this is for Oracle XE, but should be applicable for any Oracle version 9i onwards. Here's the hibernate.cfg.xml configuration for connecting to an Oracle XE. Importantly, if you're using hibernate 3.3+ you can skip the dialect setting because it'll auto-detect the dialect beautifully.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.pool.OracleDataSource</property>
    <property name="connection.url">jdbc:oracle:thin:@myhost:1521/xe</property>
    <property name="connection.username">myusername</property>
    <property name="connection.password">mypassword</property>
    <!-- etc ... !->>
  </session-factory>
</hibernate-configuration>
If you don't trust the dialect autodetection, you can prove it's working by looking in the console log to see which dialect it chose. Here's what it chose for me, using Oracle XE. It looks like its guess was spot on:
2515 [main] INFO  org.hibernate.dialect.Dialect  - 
  Using dialect: org.hibernate.dialect.Oracle10gDialect
Now for drivers. You really need the latest JDBC type 4 driver you can find, because the older ones are buggy. For instance, i was getting the following error with an older driver: "SEVERE: Error while registering Oracle JDBC Diagnosability MBean". Here's where you can find the latest Oracle JDBC drivers. Even though i'm using Oracle XE which is 10g, i downloaded the latest 11g driver. You only need either ojdbc5.jar (for java 5) or ojdbc6.jar (Java 6) according to which version of Java you're deploying to. So copy your ojdbc5/6.jar to your WebContent/WEB-INF/lib folder and you'll be good to go! No other client is needed. Good luck

Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

Chris Hulbert

(Comp Sci, Hons - UTS)

iOS Developer (Freelancer / Contractor) in Australia.

I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!

Get in touch:
[email protected]
github.com/chrishulbert
linkedin
my resume



 Subscribe via RSS