db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean T. Anderson" <...@bristowhill.com>
Subject How to run the Apache DB Torque tutorial with Derby
Date Wed, 05 Oct 2005 23:08:43 GMT
Apache DB Torque is a persistence layer that does object mapping between 
java objects and a relational database.

Torque works with Derby, thought it isn't visible on the Torque web site 

Torque 3.2-rc2 has a good tutorial based on mysql:


Below are the changes required for each step to run the tutorial on 
Derby 10.1 using the embedded driver. Switching it to the network server 
and the Derby Network Client should be easy, just a matter of changing 
the driver and the connection URLs where needed, but I haven't tested 
that yet.

Step 1
No changes.

Step 2

Here is the complete project.properties file:

    # The name of the project Torque will generate code for.
    torque.project = bookstore

    # The target database platform.
    torque.database = derby

    # The target package to put the generated classes in.
    torque.targetPackage = com.kazmier.om

    # The JDBC URL that Torque can use to create and
    # drop databases if instructed to do so.
    # Derby note: Manually create/drop databases
    torque.database.createUrl =

    # The JDBC URL that will be used to create tables in your database.
    torque.database.buildUrl = jdbc:derby:bookstore

    # The JDBC URL that will be used to access your database.
    torque.database.url = jdbc:derby:bookstore

    # The JDBC database driver to use when connecting to your database.
    torque.database.driver = org.apache.derby.jdbc.EmbeddedDriver

    # The administrative username that has sufficient privileges to create
    # and drop databases and tables that Torque executes at generation time.
    torque.database.user = app

    # The administrative password for the supplied username.
    torque.database.password = app

    # The hostname or IP address of your database server.
    torque.database.host =

Step 3

Adding the driver to the maven repository

I added the Derby 10.1 jar to my local maven repo like this:

   mkdir ~/.maven/repository/derby
   mkdir ~/.maven/repository/derby/jars
   cp /opt/Apache/db-derby- 

I'm sure there are other ways to do this that don't require renaming the 
jar to include the version.

Specifying the driver dependency

Here is the complete project.xml file:




Creating the database

The instructions mention that 'maven torque:create-db' won't work for
all databases, and I didn't find a way to make it work for Derby.
(I also didn't try very hard, so it might be possible.)

At any rate, I manually created the database in the root directory of
my torque project like this:

    java org.apache.derby.tools.ij
    ij version 10.1
    ij> connect 'jdbc:derby:bookstore;create=true';
    ij> quit;

Creating the tables

There's an issue with the project-schema.sql script that torque generates;
it creates a BOOK table that references two tables that don't exist yet
(publisher and author).  You could edit the file to swap the CREATE 
around, or run the table creates twice. I'll mention this issue to the
torque developers.

Here are two strategies that both work, one using maven and the other 
using ij.

Create the tables with maven:

    maven torque:id-table-init-sql
    maven torque:insert-sql
    maven torque:insert-sql

Create the tables manually:

    java org.apache.derby.tools.ij
    ij version 10.1
    ij> connect 'jdbc:derby:bookstore';
    ij> run 'target/sql/id-table-schema.sql';
    ij> run 'target/sql/project-schema-idtable-init.sql';
    ij> run 'target/sql/project-schema.sql';
    ij> run 'target/sql/project-schema.sql';
    ij> quit;

Step 4

Setting up the classpath
The version for the village dependency defined in this step 
does not match Step 6; so set it as shown below:


Torque Run-Time Properties

Here is the complete src/conf/torque.properties file:

    torque.database.default = bookstore
    torque.database.bookstore.adapter = derby

    #Using commons-dbcp
    torque.dsfactory.bookstore.factory = 
    torque.dsfactory.bookstore.connection.driver = 
    torque.dsfactory.bookstore.connection.url = jdbc:derby:bookstore
    torque.dsfactory.bookstore.connection.user = app
    torque.dsfactory.bookstore.connection.password = app

Step 5
No changes.

Step 6

Running the sample application

I made two modifications:

  - Explicitly specify the derby system home

  - Replace the mysql jar with the derby jar

Here's the command I ran -- and that succeeded:

[jta@gertie target]$ java 
-Dderby.system.home=/home/jta/Apache/TorqueTutorial -cp 


View raw message