JPAContainer with Spring EntityManager

I’m trying to use a JPAContainer with an EntityManager and transaction managed by Spring.
I use SpringVaadinIntegration add-on to inject an EntityManager in my UI and create the JPAContainer with

JPAContainerFactory.make(Entity.class, entityManager);

This work fine to load the entities, but fail when adding a new one with this exception

java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead

I suppose that this is because the JPAContainer try to create a JPA transaction but the EntityManager expect a Spring transaction as it is managed by Spring.

Is there a way to tell the JPAContainer to use Spring transactions instead of JPA transactions?


I have same error, did you find how to solve it ?

Hi, I’d suggest to forget the JPAContainer. If you have a Spring Data repository, you can really easily and efficiently wire it to Table/ComboBox using Viritin. Check out
my recent arcticle
about it.


Thank you for replay !
I found this example -

for building container need to use with EntityManager like

@PersistenceContext(unitName = "customerdb") EntityManager em; and after it all queries need to create manualy like:

public List getGroups() {
   return em.createQuery("SELECT e from PhoneBookGroup e",
[/code]Is it posible to use with basic spring JpaRepository object (that I already have in my old project) to build Container for vaadin like [code]
public interface BookRepository extends JpaRepository<PhoneBookGroup, Long> {
    List<PhoneBookGroup> findByTitle(String title);

Please, post link to example or documentation with using spring data and viritin container together if you have?
Thank you !


I added one here:


GRATE !!! Thank you, It’s works !!!

Do you have some example for table with real pagination, I mean that next page downloads from server side with objects Pageable and PageRequest ?

Thank you !