There are a couple of changes I'd propose here, but I'd leave this for Custom Persisters support, which will probably change this implementation a bit.