More refactoring and testing on the JPA part.

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>