Skip navigation
2007

Galder Zamarreno's Blog

April 2007 Previous month Next month

 

Integrating open source projects can sometimes be a painful task, especially when it's hard to find relevant examples that show useful capabilities and which developers can use as a starting point for their applications.

 

Hibernate and JBoss Cache have been flirting with each other, but this has now matured. We don't have to hacer de Celestina anymore as they're "married" now! Both projects know more about each other than ever before and thanks to the efforts of the developers from both projects, especially the Leads, we are now able to instruct users on how to configure them to work together in the most efficient way. However, people like to experiment and examples are of paramount importance. Over the last week I've been working on a standalone example which uses Hibernate together with JBoss Cache as a second level cache.

 

The first issue I had to tackle was whether to build a Hibernate application from scratch or use an existing one. That's when I remembered about the Hibernate tutorial and looking through it, it had all the elements I wanted to show off JBoss Cache as a second level cache, i.e. entities, collections, etc... For improved concurrency I wanted to configure JBoss Cache with an Optimistic locking scheme, but for this I needed a standalone transaction manager. Enter the room, JBoss Transactions.

 

JBoss Transactions is a very powerful transaction engine which was acquired from Arjuna. It is far superior to JBoss TM, with full recovery as one of its most interesting features, fullfilling the ACID properties. This will be the transaction manager for JBoss 4.2.x and 5. Integrating JBoss Transactions with Hibernate and JBoss Cache in this standalone example was just a matter of implementing org.jboss.transaction.TransactionManagerLookup to return the Arjuna Transaction Manager, easy peasy.

 

The next obstacle was piecing together the necessary configuration for which I used the JBoss Cache with Hibernate wiki article and the Hibernate documentation. We hope to feed this example back to the Hibernate tutorial where we'll be explaining how to create the example step by step.

 

Finally, I wanted to have a view of the 2nd level cache so that I could see how my entities/collections/queries were cached. For that, I decided to run the example with Java 5 and enable the JMX agent for local access (-Dcom.sun.management.jmxremote). If you then start the JConsole, you should be able to hook into the running Agent where TreeCacheMBean should be registered and call printDetails() to show the contents of the cache.

 

For more details and to download the example itself, visit the standalone example in the wiki.

Filter Blog

By date: