JPAContainer with Spring EntityManager

Hi,
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?

Thanks.

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.

cheers,
matti

Thank you for replay !
I found this example -
https://github.com/mstahv/vaadin-java-ee-essentials-example/tree/viewmenujpa

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",
   PhoneBookGroup.class).getResultList();
}
[/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 !

Hi,

I added one here:
https://github.com/mstahv/spring-data-vaadin-crud/blob/0f526e7130ba0be1e68d719cc985f37bd976b893/src/main/java/crud/vaadin/MainUI.java#L68-L71

cheers,
matti

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 !