Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

hibernate.cfg.xml Settings for Derby, Oracle and H2

DZone's Guide to

hibernate.cfg.xml Settings for Derby, Oracle and H2

· Database Zone ·
Free Resource

Databases are better when they can run themselves. CockroachDB is a SQL database that automates scaling and recovery. Check it out here.

It took me some time to collect the hibernate.cfg.xml data which is necessary for Derby, Oracle and H2. So here are the default settings for those databases:

Apache Derby (network)

You start the network server and specify the following options in the script:

Linux: DERBY_OPTS=”-Dij.driver=org.apache.derby.jdbc.ClientDriver -Dij.protocol=jdbc:derby://localhost:1527/ -Dij.user=admin -Dij.password=admin”Windows: set DERBY_OPTS=”-Dij.driver=org.apache.derby.jdbc.ClientDriver -Dij.protocol=jdbc:derby://localhost:1527/ -Dij.user=admin -Dij.password=admin”
<property name=”hibernate.connection.driver_class”>org.apache.derby.jdbc.ClientDriver</property><property name=”hibernate.connection.url”>jdbc:derby://localhost:1527/databaseName;create=true</property><property name=”hibernate.connection.username”>admin</property><property name=”hibernate.connection.password”>admin</property><!– no schema necessary –><property name=”hibernate.dialect”>org.hibernate.dialect.DerbyDialect</property>

Oracle(Thin) 

<property name=”hibernate.connection.driver_class”>oracle.jdbc.driver.OracleDriver</property><property name=”hibernate.connection.url”>jdbc:oracle:thin:@host:1521:databaseName</property><property name=”hibernate.connection.username”>YOURSCHEMA</property><property name=”hibernate.connection.password”>YOURPASSWORD</property><property name=”hibernate.default_schema”>YOURSCHEMA</property><property name=”hibernate.dialect”>org.hibernate.dialect.OracleDialect</property>

H2

<property name=”hibernate.connection.driver_class”>org.h2.Driver</property><property name=”hibernate.connection.url”>jdbc:h2:path\databaseName</property><property name=”hibernate.connection.username”>sa</property><property name=”hibernate.connection.password”></property><property name=”hibernate.default_schema”>PUBLIC</property><property name=”hibernate.dialect”>org.hibernate.dialect.H2Dialect</property>

To make it complete here are the Maven settings for the databases:

Apache Derby (network)

<dependency><groupId>org.apache.derby</groupId><artifactId>derbyclient</artifactId><version>10.4.2.0</version></dependency>

Oracle (thin)

No public version is available but you could install the jar file into your local repository or into an archiva repository via:

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.1.0.7.0 -Dpackaging=jar -Dfile=/path/to/file 
<dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.1.0.7.0</version></dependency>

H2

Databases should be easy to deploy, easy to use, and easy to scale. If you agree, you should check out CockroachDB, a scalable SQL database built for businesses of every size. Check it out here. 

Topics:
java ,sql ,frameworks ,persistence

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}