Custom Audit Log With Spring And Hibernate

July 18, 2016

If you need to have automatic auditing of all database operations and you are using Hibernate…you should use Envers or spring data jpa auditing. But if for some reasons you can’t use Envers, you can achieve something similar with hibernate event listeners and spring transaction synchronization. First, start with the event listener. You should capture […]


Spring-Managed Hibernate Event Listeners

July 15, 2016

Hibernate offers event listeners as part of its SPI. You can hook your listeners to a number of events, including pre-insert, post-insert, pre-delete, flush, etc. But sometimes in these listeners you want to use spring dependencies. I’ve written previously on how to do that, but hibernate has been upgraded and now there’s a better way […]


Pretty Print JSON Per Request With Spring MVC

February 22, 2016

You will find a lot of posts and stackoverflow answers telling you how to pretty-print JSON responses. But sometimes you may need to tune the “prettiness” per request. The use case for this is when you are using tools like curl or RESTClient to interact with the system and you want human-readable output. Of course, […]


Setting Up Distributed Infinispan Cache with Hibernate and Spring

February 17, 2016

A pretty typical setup – spring/hibernate application that requires a distributed cache. But it turns out not so trivial to setup. You obviously need cache. There are options to do that with EhCache, Hazelcast, Infinispan, memcached, Redis, AWS’s elasticache and some others. However, EhCache supports only replicated and not distributed cache, and Hazelcast does not […]


WebSocket and Java

December 16, 2013

WebSocket is a cool new(ish) technology that allows real-time, two-way communication between the browser and the server, with almost no overhead. What I want to do here, is to provide a very succinct, but sufficient overview of how to start using the technology. So, a few things to start with: a tcp socket connection is […]


Be Careful With Cache Managers

January 3, 2013
Tags: ,

If you are using spring and JPA, it is very likely that you utilize ehcache (or another cache provider). And you do that in two separate scenarios: JPA 2nd level cache and spring method caching. When you configure your application, you normally set the 2nd level cache provider of your JPA provider (hibernate, in my […]


How To Provide Default Serialization Format With Spring MVC RESTful Services

November 9, 2012

Spring MVC allows you to serialize objects with @ResponseBody to any format – it has built-in converters for JSON and XML. However, even though your application may support both, you may need a default in case the Accept header is not set. Furthermore (this is a strange case, but we had it), you may want […]


Spring MVC Basics – Presentation

February 3, 2012

Here are the slides for my presentation during the first DZone VIP meetup in Bulgaria. The presentation is short, and the slides can definitely be better, but I’m sharing it anyway.


Customizing Parameter Names When Binding Spring MVC Command Objects

February 2, 2012

In spring MVC you can have But that means “jobType” and “location” are the http parameter names, and there is no way to customize that. Which is odd, since this is meta-data, and it should be configurable by annotations. But if you need to customize them (for example, for SEO reasons), you can plug some […]


Spring-managed Hibernate Listeners with JPA

September 28, 2011

Update: now there’s a better way to do that. A standard use-case – you need an entity listener in order to execute some code on every update/insert/delete. For auditing, for example. But things are not straightforward if you need spring dependencies in your listeners and you are using JPA. First of all, the JPA-only listeners […]