New Spring JPAContainer EntityProvider?

I just realized that the suggested Spring Transaction Entity Provider from the JPAContainer manual includes notifying listeners within the transaction, and it’s also very much copy-paste when a new entity should be handled. I wrote up a suggestion for a new class with the same purpose. I’d be happy to receive feedback on it.

public abstract class TransactionalEntityProvider<T> extends MutableLocalEntityProvider<T> {

    private EntityManager em;

    public TransactionalEntityProvider(Class<T> entityClass) {

    public void init() {
         * The entity manager is transaction scoped, which means that the entities will be automatically detached when the transaction is
         * closed. Therefore, we do not need to explicitly detach them.

    @Transactional(propagation = Propagation.REQUIRED)
    protected void runInTransaction(Runnable operation) {

    public T updateEntity(final T entity) {
        return super.updateEntity(entity);

    public T addEntity(final T entity) {
        return super.addEntity(entity);

    public void removeEntity(final Object entityId) {

    public void updateEntityProperty(final Object entityId, final String propertyName, final Object propertyValue)
            throws IllegalArgumentException {
        super.updateEntityProperty(entityId, propertyName, propertyValue);

And an implementation would look like

public class BoatEntityProvider extends TransactionalEntityProvider<Boat> {
    protected BoatEntityProvider() {

Hi Fredrik,

This looks great, Most of the spring transaction managment i’ve seen in vaadin involves using the opensessioninviewfilter so that any entitiy changes are automagically persisted, however in enterprise apps you really want more control of exactly how and when changes get writen back to the db.

Originally I tried calling a one-line @tranactional method around the container.commit() call in order to get spring to manage my transactions declaritively, however this was pretty messy and inelegant.

I like the look of your entitiy provider and will give it go. I will also compare it with the version you reference in the jpaContainer manual.