Spring, JPA, and JTA with Hibernate and JOTM
2007-04-24 20:35
have been struggling for a couple of hours today to modify a Spring JPA configuration with a single datasource, Hibernate as the JPA provider and the JpaTransactionManager to a configuration with two XA datasources, Hibernate as the JPA provider, and the JtaTransactionManager with JOTM as the standalone JTA provider.
since the Spring and Hibernate reference manual and Javadoc documentation merely contain a number of hints on how to configure JPA with a JTA transaction manager and others are struggling as well i decided to post how i finally got it to work.
The Eclipse Persistence Services Project (EclipseLink) project's goal is to provide a complete persistence framework that is both comprehensive and universal. It will run in any Java environment and read and write objects to virtually any type of data source, including relational databases, XML, or EIS systems. EclipseLink will focus on providing leading edge support, including advanced feature extensions, for the dominant persistence standards for each target data source; Java Persistence API (JPA) for relational databases, Java Architecture for XML Binding (JAXB) for XML, J2EE Connector Architecture (JCA) for EIS and other types of legacy systems, and Service Data Objects (SDO).
EasyBeans is an open-source Enterprise Java Beans (EJB) container hosted by the OW2 consortium. The License used by EasyBeans is the LGPL.
EasyBeans main goal is to ease the development of Enterprise Java Beans. It uses some new architecture design like the bytecode injection (with ASM ObjectWeb tool), IoC, POJO and can be embedded in OSGi bundles or other frameworks (Spring, Eclipse plugins, etc.).
It aims to provide an EJB3 container as specified in the Java Platform Enterprise Edition (Java EE) in its fifth version. It means that Session beans (Stateless or Stateful), Message Driven Beans (MDB) are available on EasyBeans.
The new persistence layer used by EJB 3.0 is now called Java Persistence API (or JPA). It replaces the CMP (Container Managed Persistence) model used by EJB 2.x. The default persistence provider used in EasyBeans is Hibernate Entity Manager or Apache OpenJPA but other JPA providers have been tested like for example Oracle TopLink Essentials.
The Envers project aims to enable easy versioning of persistent JPA classes. All that you have to do is annotate your persistent class or some of its properties, that you want to version, with @Versioned. For each versioned entity, a table will be created, which will hold the history of changes made to the entity. You can then retrieve and query historical data without much effort.
Similarly to Subversion, the library has a concept of revisions. Basically, one transaction commit is one revision (unless the transaction didn't modify any versioned entities). As the revisions are global, having a revision number, you can query for various entities at that revision, retrieving a (partial) view of the database at that revision.
What is Ebean?
Ebean is a Object Relational Mapping Persistence Layer written in Java (Open Source LGPL license).
* Providing the features of EJB3's JPA (and more)
* No container required
* JPA compatible ORM mapping (@Entity, @OneToMany, ...)
Why use Ebean?
Ebean provides a simpler approach to Object Relational Mapping. It does this by not requiring session objects such as JPA EntityManager, JDO PersistenceManager, Hibernate Session, Toplink ClientSession.
JSF-Spring-JPA is the popular stack of choice these days, mostly to be used in my consulting and training purposes I’ve created a base project called MovieStore demonstrating the annotation-driven integration of JSF-Spring-JPA. JSF backing beans, spring service level beans and DAO’s are configured and integrated with annotations. Only the core infrastructure like datasource, entityManagerFactory or transactionManager are configured with xml.
Java framework for CRUD and Validation.
Crank Google Group for Questions and Such
Crank is a master/detail, CRUD, and annotation driven validation framework built with JPA, JSF, Facelets and Ajax. It allows developers to quickly come up with JSF/Ajax based CRUD listings and Master/Detail forms from their JPA annotated Java objects.
Crank uses a lot of the new JSF features from Facelets, Ajax4JSF, etc. that will be used in JSF 2.0. Crank is a use case analysis of what is possible with the new JSF 2.0 stack.
The validation piece does server-side validation, Ajax validation or just emitted JavaScript validation based on Java annotations, property files, XML files, or database tables. Currently works with JSF, Spring MVC and Spring Webflow.
Apache MyFaces Orchestra aims to provide a simple way to combine a web-framework with a persistence layer. Typically, an Apache MyFaces Orchestra stack might combine JavaServer Faces, Spring and a JPA implementation like Toplink, Hibernate, etc.
The underlying idea is to provide long persistence sessions to the web-developer - this is done by associating these sessions with a conversational context.
The conversational context is opened when the bean configured for this context is first loaded. It can be manually closed by the programmer, plus a time-out can be configured as a global parameter.