28 Nov 2011

(Finally) Spring, Quartz and JPA working together

Written by ilgrosso

When writing Java code relying on Spring and JPA, you may eventually come to the need of some scheduling; since Quartz is by far the reference in this field, you think you will solve all of your problems by reading the appropriate page on Spring docs. Wrong, at least if you need some Spring goodies like @Autowired and @Transactional.

We had exactly this situation at Syncope IdM a few months ago, when implementing Synchronization tasks to external resources (like as Active Directory). After some research we went to an useful blog post (I've also reported about this topic): we only had to update some referecences from pure Hibernate to JPA, make some other minor corrections and voilà, things were - and actually, still are - working. You can see results from current Syncope trunk, if interested.

Unfortunately, every Quartz job needs three separate Spring beans and involves a JPA interceptor: a bit too much heavy, in my opinion. However, I've lately found a more appealing approach empowering latest features from Spring 3.0, so I've prepared a simple Maven project implementing suggestions reported there and adding some JPA-specific checks.

The result is now something looking more simple, elegant and functional then before: of course we will replace the correspondant implementations in Syncope IdM very soon, surely before next stable release Ritornello, expected before end of year.

I hope this will save some of your time, like it did for me :-)


« Return