db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "DerbyOnTomcatWithSpringHibernate" by JoonasKoivunen
Date Thu, 16 Apr 2009 14:00:35 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by JoonasKoivunen:
http://wiki.apache.org/db-derby/DerbyOnTomcatWithSpringHibernate

The comment on the change is:
First version, a bit unsure if this tutorial is going to be too wide scale..

New page:
= Using Derby on Tomcat Webapp built on Spring and Hibernate =

== Preface ==

This tutorial covers the steps you need to setup a multitierable web-app project with the
following ingredients:
 * Derby 10.4.2.0
 * [http://www.springframework.org Spring framework] 2.5.6
 * [http://www.hibernate.org Hibernate]
   * Core 3.3.1.GA
   * Annotations 3.4.0.GA
 * Maven 2.0.10
 * Tomcat 6.0.18
 * Java 6

The point of making this tutorial was that the only tutorials I've been able to find usually
deal with previous versions of the above and there might or might not be problems with more
recent ones.

Note that this tutorial assumes you've got some basics of Java software development and maven
already. I've done this all using Eclipse Ganymede r2 on Linux with m2eclipse plugin. It might
be doable with others as well.

Other note; I'm no master of maven, there might be public archetypes for this already floating
somewhere, linking them here might help people to get started.

== Starting up ==

=== Project structure ===

Our example project consists of the following parts:
 * exproject (maven site project, root of our project hierarchy)
  * exproject-core (entities, daos, services)
  * exproject-webapp (webapp which we are deploying on tomcat)

=== Setting it all up ===

In eclipse with m2eclipse, you'd start by taking a clean new workspace and go: 
 1. File -> New -> Other... -> Maven project
 2. Select the "Create a simple project" checkbox, hit "Next >"
 3. Fill in the artifact identification and hit "Finish" afterwards:
   * Group id: '''org.example.exproject'''
   * Artifact id: '''exproject'''
   * Packaging: '''pom'''

After a while you'll got yourself a new project; quickly add the two modules (exproject-core,
exproject-webapp) to it by selecting the "exproject" in Project Explorer, selecting "Maven
> New Maven Module Project" from the context menu. Fill the wizard as mentioned above but
use packaging "jar" for exproject-core and packaging "war" for exproject-webapp.

==== Post processing ====

By default the pom -files have explicit versions on each; however I've found it easier to
have the modules inherit the version numbers. You can accomplish this by removing version
-elements straight under the project -element (not under the parent -element!).

If you want to use generics in your project you should add this snippet into your exproject/pom.xml
file:
{{{
<project ...>
  <!-- omitted for clarity, snip here -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <!-- set the output classfiles to require Java6 runtime, you can also use 1.5
here -->
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
}}}

==== Adding dependencies ====

Hint on maintaining correct versions of your dependencies: Put them under properties like
(add under project -element in exproject/pom.xml):
{{{
<properties>
  <derby.version>10.4.2.0</derby.version>
</properties>
}}}

You can then refer to them as with ${derby.version}.

===== Derby =====

To include derby in your core project add the following (add under project -element in exproject/exproject-core/pom.xml):
{{{
<dependencies>
  <dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>${derby.version}</version>
    <scope>test</scope> <!-- this means derby will only be available for testing
in exproject-core, 
                             will not be included to other projects using exproject-core as
dependency -->
  </dependency>
</dependencies>
}}}

If you want to use derby over network, you should add artifact ''derbyclient'' instead of
''derby.''

===== Others =====

To add (latest) hibernate dependencies you'll need to [http://www.hibernate.org/422.html add
JBoss release repository] as well.

Spring framework is available as one huge chunk and as many smaller parts, for beginner it
might be easier to just use artifact "spring-full" under group "org.springframework".

=== Actual work (exproject-core) ===

==== Entities ====
(TODO: create two simple entities that have some kind of relation to each other)

==== DAO's ====
(TODO: simple daos, HibernateDaoSupport, link to ibm generic dao article)

==== Services ====
(TODO: simple generic crud service, @Transactional)

==== Configuring ====
(TODO: Spring context:component-scan, context:annotation-config, tx:annotation-driven)

==== Testing on derby ====
(TODO: create/upload schema with hbm2ddl.auto, simple crud testing, datasource)

=== Actual work (exproject-webapp) ===

==== Simple controller and view skeleton ====
(TODO: example)

==== ServletContextListener ====
(TODO: reason, usage, derby database creation, shutdown)

==== Configuration ====
(TODO: context:component-scan, datasource, web.xml)

==== Launching ====
(TODO: ...)

Mime
View raw message