Massively Scalable Applications

JEE Annotations

This tutorial consolidates a list of frequently used annotations for important JEE frameworks - Spring, Hibernate, JPA, JAXB, Web Services, and jUnit. It contains usage instructions, code examples and important tips (nitty-gritty details that every developer using these annotations should know). In this tutorial, you will also learn:

  1. How to use JAXB and Hibernate-JPA annotations in conjunction to convert your data in entity beans to XML or JSON format
  2. How to use JAX-RS with JAXB and JPA annotations to exchange data with rich clients using REST based web services
  3. How to use Spring and jUnit annotations in conjunction to test spring based applications
This is an advanced tutorial. Please see Prerequisite section below. There are many documents on the Internet that describe annotations for different frameworks in detail and some of them are mentioned in the 'References' section below. The focus of this tutorial is on frequently used annotations in multiple JEE frameworks, important tips on them and how to use them in conjunction.

This tutorial is structured into 5 parts as shown in 'Contents' table below.

Prerequisite

This tutorial assumes that the reader knows commonly used JEE technologies like Spring, Hibernate, JPA, REST, JAXB, jUnit. A basic knowledge about annotations is also required. This is NOT a step by step tutorial where you learn how to build Spring, Hibernate based applications, rather it helps you learn about frequently used annotations in multiple JEE technologies (Please see Technology Stack used in our tutorial.) You will also learn how to use annotations from different technologies in conjunction and their benefits.

Example Application

The example application we will refer in this tutorial has the following functionality:
  • Create a new company
  • Create contacts in that company
  • Display list of companies and view company detail for any company
  • Display list of contacts that belong to the selected company

Technology Stack

The focus of this tutorial is Annotations used in different JEE frameworks required for developing enterprise applications. The technologies we are using for our example application are:
  • Spring as IOC/DI framework, bean management, Spring MVC
  • Spring security for authentication and authorization
  • Hibernate -JPA as persistence framework
  • Jersey for RESTful Web Services. We will use JAX-RS annotations.
  • JAXB annotations to convert our data objects into desired JSON, XML format to be consumed by rich clients like jQuery or Ext-js
  • jUnit for unit testing our spring based application

Database Model

The database we have designed is to explain various association mappings and related annotations. The ERD for our example application database can be viewed here.

References

  1. Spring Annotations: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/beans.html#beans-annotation-config
  2. Spring Framework Reference: http://static.springsource.org/spring/docs/current/spring-framework-reference/pdf/spring-framework-reference.pdf
  3. Hibernate Annotations: http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/
  4. Inheritance Mapping Reference: http://docs.jboss.org/hibernate/core/3.5/reference/en/html/inheritance.html
  5. Jersey JAX-RS Annotations: https://wikis.oracle.com/display/Jersey/Overview+of+JAX-RS+1.0+Features
  6. JAXB Annotations: http://docs.oracle.com/javaee/6/api/javax/xml/bind/annotation/package-summary.html
  7. Annotations for Unit Testing Spring applications: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/testing.html#integration-testing-annotations