JPA persistence within JBoss 5 (not using JTA)

I’ve recently been working on a task involving JPA persistence within a servlet running in JBoss 5.  My servlet hasn’t been built using EJB, so at this stage I haven’t been using the JTA to manage my database transactions. 

People more experienced than me assure me that it is good practice to use EJB, and use the JTA to manage transactions, as it will do a much better job than I ever could, so this will be a task for the near future.

However, in the meantime, I’m not using JTA.  I’m using the Hibernate implementation of JPA provided within JBoss.  The first thing you need to do to not use JTA is to set the transaction-type of the persistence-unit to RESOURCE_LOCAL.  You then need to specify a non-jta-data-source within persistence.xml.

You define your data source within an xml file, and then add a module to the jboss-app.xml file within your servlet which references the data source file as a service.

I was using the H2 database.  I found that I had to copy the h2*.jar file into JBOSS_HOME/server/default/lib in order for JBoss to find the jdbc driver classes.

To manage transactions, I found I had to follow the following workflow:

get entity manager from factory -> begin transaction -> do work -> commit -> close the entity manager.

And thats it.  Hopefully further posts to follow regarding using EJB and JTA.

Updating hot deployment scan period in JBoss 5

The default scan period was set to 60 seconds.  During development, I wanted a shorter waiting period before my new version of a .war file was deployed.  This can be changed by editing hdscanner-jboss-beans.xml within the deploy folder.

The HDScanner bean contains a property “scanPeriod”, which specifies the interval at which JBoss scans for new deployments.

Error when starting JBoss in Linux

When starting up the JBoss application server, I was getting some weird errors being logged at the start, regarding “command not found” when parsing the run.conf file.

It turned out the issue was due to the run.conf file having Windows style line endings, and it wasn’t being read correctly in Linux.

To fix this, I converted the file using dos2linux on the command line.