Cheat Sheet: New Features in JPA 2.1

JPA 2.1 introduced 12 new features, like StoreProcedureQueries, Entity Graphs and Attribute Converter, to make your work with the database easier and more efficient.
Download your free New Features in JPA 2.1 cheat sheet now, to get all the information you need to improve your database access.

This 5 page cheat sheet brings you:

- a short description and
- code snippets for each feature,
- links to more detailed articles.

Signup now and get your free New Features in JPA 2.1 cheat sheet and regular blog updates.

I respect your privacy and have ZERO TOLERANCE for spam!

JBoss Forge - Speedup your enterprise development

Hello and welcome to my blog!

In my first posting I want to show how to create a maven based Java EE project within 5 minutes with JBoss Forge. We will create a project with two entities (Book and Author) and a web interface to create, search and edit these objects.

This is the first part of my JBoss Forge series:

Getting JBoss Forge

The easiest way to get JBoss Forge is to use JBoss Tools or JBoss Developer Studio. You can find both in the Eclipse Marketplace.
After installing the plugin to your eclipse, you need to start the Forge Console to get the command line interface.


Create the project

We could spend some time to create the project with the eclipse wizard and to setup the maven build process. But using Forge is much easier and faster. By entering the following command to the Forge Console we are getting a project ready to start with the real work:

After providing the project directory, Forge creates a new project with a maven build process and updates eclipse.


Generate Persistence

OK, now we can start to build our application. Lets do the persistence first.
In the past we created - or most often copied - the persistence.xml file. Now we can use Forge to create the persistence.xml file:

We need to provide the provider and container which shall be used to generate the configuration. We can choose between Hibernate, OpenJPA, EclipseLink and Infinispan as a persistence provider. Different JBoss AS and EAP versions, Wildfly, GlassFish, WebLogic and others can be used as container. The JNDI name of the data source and others can be provided as optional parameters.
Forge keeps the Package Explorer up to date and opens the persistence.xml in an editor:

Now we can start to generate our entities. First we create the entity Book with a title as String, the publicationDate as Date and the number of pages as int. This can be done in four lines by using the commands entity and field:

We do the same to create the Author entity:

The last thing missing is the association between Author and Book. We create a one-to-many association between Author and Book in this example:

The result is a very clean implementation of the two entities which can be seen in the eclipse editor. Each generation step updates the eclipse editor immediately so that we always see whats happening. Forge creates the required annotations, get() and set() methods. So we can be sure that we have all required annotations in the right place. Even the methods equals(), hashCode() and toString() are created. Here you can see the generated Author entity:


Generate Web UI

Now we are only missing the web interface for the created entities. Therefore we setup the scaffolding and generate the web interface from our entities. In this example we use the default scaffold type JavaServer Faces.

We need a war project to deploy our web interface, but up to now it was a jar project. Forge detects this during the generation of the web interface and and offers to update the packaging. By updating the packaging of our application, forge adds the missing dependencies and updates our project.

After the generation is done, we can build our application by calling build or by using the normal maven commands.



As a last step we want to deploy our application to a JBoss AS7 instance. This can be done with the AS7 Forge Plugin. Therefore we need to install and configure it:

During the setup process we need to provide the Java Home and a default version of the application server. Additionally we can provide the path to an installed JBoss AS or let Forge do this for us.
Now we can start the server and deploy the application by calling a7 deploy.

OK, lets have a look at our application:



We created a Java EE project in less than 5 minutes by using just a few commands of JBoss Forge. But you can do much more with JBoss Forge. In my next post I will show you how to generate a webservice interface for our application and how to use the arquillian plugin to test it.



JBoss Forge Series


      1. This looks exactly like Spring Roo (even syntactically):

        Where's the difference?

      2. Thank you for your question.

        Forge and Spring Roo are similar in several aspects. The main difference for me is, that Spring Roo and the generated projects are tied to Spring (generated projects work on top of Spring). Projects created by Forge are only based on Maven. So the Forge approach is far more generic than Spring Roo.

        The Forge FAQ provides a more detailed answer for your question:

      3. Great work - Forge and your article as well! As a shell enthusiast I like the use of Forge as some kind of project shell. Really curious to see the next part of your tutorial. BTW: Don't miss to include examples of the scripting features. :-)

        1. Thank you Ronny!

          The next part is already up:
          And I will post a third part beginning of next week :)

      4. Hi, thanks for the quick reply. I just watched a 1hr demo on it and im quite impressed. Thanks for the tip! I reckon ill give it a shot.